D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
opt
/
psa
/
admin
/
plib
/
modules
/
catalog
/
vendor
/
tedivm
/
stash
/
tests
/
Stash
/
Test
/
Filename :
ItemLoggerTestCase.php
back
Copy
<?php /* * This file is part of the Stash package. * * (c) Robert Hafner <tedivm@tedivm.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PleskCatalog\Stash\Test; use PleskCatalog\Stash\Test\Stubs\LoggerStub; use PleskCatalog\Stash\Test\Stubs\DriverExceptionStub; use PleskCatalog\Stash\Test\Stubs\PoolGetDriverStub; use PleskCatalog\Stash\Item; use PleskCatalog\Stash\Driver\Ephemeral as Ephemeral; /** * @package Stash * @author Robert Hafner <tedivm@tedivm.com> */ class ItemLoggerTestCase extends AbstractTestCase { protected function getItem($key, $exceptionDriver = \false) { if ($exceptionDriver) { $fullDriver = 'PleskCatalog\\Stash\\Test\\Stubs\\DriverExceptionStub'; } else { $fullDriver = 'PleskCatalog\\Stash\\Driver\\Ephemeral'; } $item = new Item(); $poolStub = new PoolGetDriverStub(); $poolStub->setDriver(new $fullDriver()); $item->setPool($poolStub); $item->setKey($key); return $item; } public function testSetLogger() { $item = $this->getItem(array('path', 'to', 'constructor')); $logger = new LoggerStub(); $item->setLogger($logger); $this->assertAttributeInstanceOf('PleskCatalog\\Stash\\Test\\Stubs\\LoggerStub', 'logger', $item, 'setLogger injects logger into Item.'); } public function testGet() { $logger = new LoggerStub(); $item = $this->getItem(array('path', 'to', 'get'), \true); $item->setLogger($logger); // triggerlogging $item->get('test_key'); $this->assertInstanceOf('PleskCatalog\\Stash\\Test\\Exception\\TestException', $logger->lastContext['exception'], 'Logger was passed exception in event context.'); $this->assertTrue(\strlen($logger->lastMessage) > 0, 'Logger message set after "get" exception.'); $this->assertEquals('critical', $logger->lastLevel, 'Exceptions logged as critical.'); } public function testSet() { $logger = new LoggerStub(); $item = $this->getItem(array('path', 'to', 'set'), \true); $item->setLogger($logger); // triggerlogging $item->set('test_key')->save(); $this->assertInstanceOf('PleskCatalog\\Stash\\Test\\Exception\\TestException', $logger->lastContext['exception'], 'Logger was passed exception in event context.'); $this->assertTrue(\strlen($logger->lastMessage) > 0, 'Logger message set after "set" exception.'); $this->assertEquals('critical', $logger->lastLevel, 'Exceptions logged as critical.'); } public function testClear() { $logger = new LoggerStub(); $item = $this->getItem(array('path', 'to', 'clear'), \true); $item->setLogger($logger); // triggerlogging $item->clear(); $this->assertInstanceOf('PleskCatalog\\Stash\\Test\\Exception\\TestException', $logger->lastContext['exception'], 'Logger was passed exception in event context.'); $this->assertTrue(\strlen($logger->lastMessage) > 0, 'Logger message set after "clear" exception.'); $this->assertEquals('critical', $logger->lastLevel, 'Exceptions logged as critical.'); } }