| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Onoi\BlobStore\Tests; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Onoi\BlobStore\Container; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * @covers \Onoi\BlobStore\Container | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * @group onoi-blobstore | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * @license GNU GPL v2+ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * @since 1.0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * @author mwjames | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | class ContainerTest extends \PHPUnit_Framework_TestCase { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | 	public function testCanConstruct() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | 		$this->assertInstanceOf( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | 			'\Onoi\BlobStore\Container', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | 			new Container( 'Foo', array() ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | 		); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | 	public function testTryToConstructForInvalidIdThrowsException() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | 		$this->setExpectedException( 'InvalidArgumentException' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | 		new Container( array(), array() ); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | 	public function testGetIdAndData() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | 		$expected = array( 'Bar' => new \stdClass ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | 		$instance = new Container( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | 			'Foo', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  | 			$expected | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | 		); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | 		$this->assertEquals( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | 			'Foo', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | 			$instance->getId() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | 		); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | 		$this->assertEquals( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  | 			$expected, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | 			$instance->getData() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  | 		); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  | 		$this->assertFalse( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  | 			$instance->isEmpty() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  | 		); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  | 	public function testExpiry() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  | 		$instance = new Container( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  | 			'Foo', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  | 			array() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  | 		); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  | 		$instance->setExpiryInSeconds( 42 ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  | 		$this->assertSame( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  | 			42, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  | 			$instance->getExpiry() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  | 		); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  | 	public function testGetAndSet() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  | 		$expected = array( 'Bar' => new \stdClass ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  | 		$instance = new Container( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  | 			'Foo', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  | 			$expected | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  | 		); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  | 		$this->assertFalse( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  | 			$instance->get( 'foobar' ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  | 		); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  | 		$this->assertEquals( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  | 			new \stdClass, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  | 			$instance->get( 'Bar' ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  | 		); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  | 		$instance->set( 'Bar', 42 ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  | 		$this->assertEquals( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  | 			42, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  | 			$instance->get( 'Bar' ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  | 		); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  | 		$instance->append( 'Bar', 1001 ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  | 		$this->assertEquals( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  | 			array( 42 , 1001 ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  | 			$instance->get( 'Bar' ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  | 		); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  | 		$instance->append( 'foobar', 1001 ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  | 		$this->assertEquals( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  | 			array( 1001 ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  | 			$instance->get( 'foobar' ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  | 		); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  | 	public function testHasAndDelete() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  | 		$expected = array( 'Bar' => new \stdClass ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  | 		$instance = new Container( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  | 			'Foo', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  | 			$expected | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  | 		); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  | 		$this->assertTrue( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  | 			$instance->has( 'Bar' ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  | 		); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  | 		$instance->delete( 'Bar' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  | 		$this->assertFalse( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  | 			$instance->has( 'Bar' ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  | 		); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  | 	} | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 130 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 131 |  |  | 	public function testAddToLinkedList() { | 
            
                                                                        
                            
            
                                    
            
            
                | 132 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 133 |  |  | 		$instance = new Container( | 
            
                                                                        
                            
            
                                    
            
            
                | 134 |  |  | 			'Foo' | 
            
                                                                        
                            
            
                                    
            
            
                | 135 |  |  | 		); | 
            
                                                                        
                            
            
                                    
            
            
                | 136 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 137 |  |  | 		$instance->addToLinkedList( 'Bar' ); | 
            
                                                                        
                            
            
                                    
            
            
                | 138 |  |  | 		$instance->addToLinkedList( 'Bar' ); | 
            
                                                                        
                            
            
                                    
            
            
                | 139 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 140 |  |  | 		$this->assertEquals( | 
            
                                                                        
                            
            
                                    
            
            
                | 141 |  |  | 			array( 'Bar' ), | 
            
                                                                        
                            
            
                                    
            
            
                | 142 |  |  | 			$instance->getLinkedList() | 
            
                                                                        
                            
            
                                    
            
            
                | 143 |  |  | 		); | 
            
                                                                        
                            
            
                                    
            
            
                | 144 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 146 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 147 |  |  |  | 
            
                        
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: