예제 #1
0
 public function testInvalidSource()
 {
     $container = new Container();
     $source = [];
     $container->setSource($source);
     $this->setExpectedException(\Lucid\Container\Exception\InvalidSourceException::class);
     $invalidSource = 'hi';
     $container->setSource($invalidSource);
 }
예제 #2
0
 public function testArray()
 {
     $container = new Container();
     $container->set('testKey', '1,2,3');
     $this->assertTrue($container->has('testKey'));
     $this->assertTrue(count($container->array('testKey')) == 3);
     $this->assertTrue($container->array('testKey')[1] == 2);
     $container->delete('testKey');
     $this->assertFalse($container->has('testKey'));
     $container->set('testKey', '1|2|3');
     $this->assertTrue($container->array('testKey', [], '|')[1] == 2);
 }
예제 #3
0
 public function testDoubleDecorator()
 {
     $container = new Container();
     $dec1 = new PrefixDecorator('dec1:', $container);
     $dec2 = new PrefixDecorator('dec2:', $dec1);
     $container->set('rootindex', 'rootvalue');
     $dec1->set('dec1index', 'dec1value');
     $dec2->set('dec2index', 'dec2value');
     $this->assertEquals('rootvalue', $container->get('rootindex'));
     $this->assertEquals('dec1value', $container->get('dec1:dec1index'));
     $this->assertEquals('dec2value', $container->get('dec1:dec2:dec2index'));
     $this->assertEquals('rootvalue', $dec1->get('../rootindex'));
     $this->assertEquals('dec1value', $dec1->get('dec1index'));
     $this->assertEquals('dec2value', $dec1->get('dec2:dec2index'));
     $this->assertEquals('rootvalue', $dec2->get('../../rootindex'));
     $this->assertEquals('dec1value', $dec2->get('../dec1index'));
     $this->assertEquals('dec2value', $dec2->get('dec2index'));
 }
예제 #4
0
 public function testDateTime()
 {
     $container = new Container();
     $container->set('unix_jan1_1970', 1);
     # $container->set('iso8601_jan1_1970', );
     $dt1 = $container->DateTime('unix_jan1_1970');
     $this->assertEquals(get_class($dt1), 'DateTime');
     $this->assertEquals($dt1->format(\DateTime::ISO8601), '1970-01-01T00:00:01+0000');
     $this->assertEquals($dt1->format('U'), 1);
     $container->set('iso8601_jan1_1970', $dt1->format(\DateTime::ISO8601));
     $dt2 = $container->DateTime('iso8601_jan1_1970');
     $this->assertEquals($dt2->format(\DateTime::ISO8601), '1970-01-01T00:00:01+0000');
     $this->assertEquals($dt2->format('U'), 1);
     $container->set('goingToError', 'hello');
     $this->setExpectedException(\Lucid\Container\Exception\DateTimeParseException::class);
     $container->DateTime('goingToError');
 }