Source of file StorageTest.php
Size: 3,513 Bytes - Last Modified: 2021-12-24T06:51:36+00:00
/var/www/docs.ssmods.com/process/src/tests/Storage/StorageTest.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 | <?php namespace Heystack\Core\Storage; use Heystack\Core\Identifier\Identifier; class StorageTest extends \PHPUnit_Framework_TestCase { const MOCK_IDENTIFIER = 'test'; /** * @var \Heystack\Core\Storage\BackendInterface */ protected $mockBackend; protected function setUp() { $this->mockBackend = $this->getMock('Heystack\Core\Storage\BackendInterface'); $this->mockBackend->expects($this->any()) ->method('getIdentifier') ->will($this->returnValue(new Identifier(self::MOCK_IDENTIFIER))); } /** * @covers \Heystack\Core\Storage\Storage::__construct */ public function testObjectCanBeConstructedWithNoArguments() { $this->assertTrue( is_object($s = new Storage()) ); return $s; } /** * @covers \Heystack\Core\Storage\Storage::__construct * @covers \Heystack\Core\Storage\Storage::setBackends */ public function testObjectCanBeConstructedWithBackends() { $this->assertTrue( is_object($s = new Storage([$this->mockBackend])) ); return $s; } /** * @covers \Heystack\Core\Storage\Storage::getBackends * @depends testObjectCanBeConstructedWithBackends */ public function testCanGetBackends(Storage $s) { $this->assertEquals( [self::MOCK_IDENTIFIER => $this->mockBackend], $s->getBackends() ); } /** * @covers \Heystack\Core\Storage\Storage::addBackend * @covers \Heystack\Core\Storage\Storage::getBackends * @depends testObjectCanBeConstructedWithNoArguments */ public function testCanAddBackend(Storage $s) { $s->addBackend($this->mockBackend); $this->assertEquals( [self::MOCK_IDENTIFIER => $this->mockBackend], $s->getBackends() ); } /** * @covers \Heystack\Core\Storage\Storage::process * @depends testObjectCanBeConstructedWithNoArguments */ public function testCanProcessStorableInterface(Storage $s) { $storable = $this->getMock( 'Heystack\Core\Storage\StorableInterface' ); $storable->expects($this->once()) ->method('getStorableBackendIdentifiers') ->will($this->returnValue([self::MOCK_IDENTIFIER])); $mockBackend = $this->getMock('Heystack\Core\Storage\BackendInterface'); $mockBackend->expects($this->any()) ->method('getIdentifier') ->will($this->returnValue(new Identifier(self::MOCK_IDENTIFIER))); $mockBackend ->expects($this->once()) ->method('write') ->with($storable) ->will($this->returnValue( $do = $this->getMock('DataObject') )); $s->addBackend($mockBackend); $results = $s->process($storable); $this->assertTrue(isset($results[self::MOCK_IDENTIFIER])); $this->assertEquals($do, $results[self::MOCK_IDENTIFIER]); } /** * @covers \Heystack\Core\Storage\Storage::__construct * @covers \Heystack\Core\Storage\Storage::process * @expectedException \Heystack\Core\Storage\Exception\StorageProcessingException */ public function testExceptionThrownDuringProcessingWithNoBackends() { (new Storage())->process( $this->getMock('Heystack\Core\Storage\StorableInterface') ); } } |