-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c725ecd
commit 3b6a5c9
Showing
8 changed files
with
299 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Presque package. | ||
* | ||
* (c) Justin Rainbow <justin.rainbow@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Presque\Tests; | ||
|
||
use Presque\Tests\TestCase; | ||
use Presque\Log\MonologLogAdapter; | ||
use Monolog\Logger; | ||
|
||
class MonologLogAdapterTest extends TestCase | ||
{ | ||
protected $logger; | ||
protected $adapter; | ||
|
||
/** | ||
* @dataProvider getLogLevels | ||
*/ | ||
public function testLoggingMessages($level, $expectedLevel) | ||
{ | ||
$this->logger | ||
->expects($this->once()) | ||
->method('addRecord') | ||
->with($this->equalTo($expectedLevel), $this->equalTo("My message")); | ||
|
||
$this->adapter->log("My message", $level); | ||
} | ||
|
||
public function getLogLevels() | ||
{ | ||
return array( | ||
array(LOG_DEBUG, Logger::DEBUG), | ||
array(LOG_INFO, Logger::INFO), | ||
array(LOG_WARNING, Logger::WARNING), | ||
array(LOG_ERR, Logger::ERROR), | ||
array(LOG_CRIT, Logger::CRITICAL), | ||
array(LOG_ALERT, Logger::ALERT), | ||
); | ||
} | ||
|
||
protected function setUp() | ||
{ | ||
$this->logger = $this->createMonologMock(); | ||
$this->adapter = new MonologLogAdapter($this->logger); | ||
} | ||
|
||
protected function createMonologMock() | ||
{ | ||
return $this->getMockBuilder('Monolog\Logger') | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Presque package. | ||
* | ||
* (c) Justin Rainbow <justin.rainbow@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Presque\Tests\Storage; | ||
|
||
use Presque\Tests\TestCase; | ||
use Presque\Storage\PredisStorage; | ||
use Mockery as m; | ||
|
||
class PredisStorageTest extends TestCase | ||
{ | ||
protected $predis; | ||
protected $storage; | ||
|
||
public function testPushingDataOntoList() | ||
{ | ||
$payload = array( | ||
'class' => 'test', | ||
'args' => array() | ||
); | ||
|
||
$this->predis | ||
->shouldReceive('lpush') | ||
->with('list', json_encode($payload)) | ||
->once(); | ||
|
||
$this->storage->push('list', $payload); | ||
} | ||
|
||
public function testPopingDataFromList() | ||
{ | ||
$payload = array( | ||
'class' => 'test', | ||
'args' => array() | ||
); | ||
|
||
$this->predis | ||
->shouldReceive('blpop')->with('list', 5)->once()->andReturn(array('list', json_encode($payload)))->ordered('pop') | ||
->shouldReceive('blpop')->with('presque:list', 5)->once()->andReturn(array('presque:list', json_encode($payload)))->ordered('pop') | ||
->shouldReceive('blpop')->with('presque:list', 5)->once()->andReturn(false)->ordered('pop') | ||
->shouldReceive('blpop')->with('presque:list', 5)->once()->andReturn(array())->ordered('pop'); | ||
|
||
$result = $this->storage->pop('list', 5); | ||
$this->assertTrue(is_array($result)); | ||
$this->assertArrayHasKey('class', $result); | ||
$this->assertArrayHasKey('args', $result); | ||
$this->assertEquals('test', $result['class']); | ||
|
||
$this->storage->setPrefix('presque'); | ||
$this->assertEquals('presque', $this->storage->getPrefix()); | ||
$result = $this->storage->pop('list', 5); | ||
$this->assertTrue(is_array($result)); | ||
$this->assertArrayHasKey('class', $result); | ||
$this->assertArrayHasKey('args', $result); | ||
$this->assertEquals('test', $result['class']); | ||
|
||
$this->assertFalse($this->storage->pop('list', 5)); | ||
$this->assertFalse($this->storage->pop('list', 5)); | ||
} | ||
|
||
protected function setUp() | ||
{ | ||
$this->predis = $this->createPredisMock(); | ||
$this->storage = new PredisStorage($this->predis); | ||
} | ||
|
||
protected function createPredisMock() | ||
{ | ||
return m::mock('Predis\Client'); | ||
} | ||
} |
Oops, something went wrong.