|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Byscripts\StaticEntity\Tests; |
| 4 | + |
| 5 | +use Byscripts\StaticEntity\StaticEntity; |
| 6 | + |
| 7 | +class StaticEntityIndirectTest extends \PHPUnit_Framework_TestCase |
| 8 | +{ |
| 9 | + public function testInstance() |
| 10 | + { |
| 11 | + /** @var $civility \Byscripts\StaticEntity\Tests\Fixtures\Civility */ |
| 12 | + $civility = StaticEntity::get('mr', '\Byscripts\StaticEntity\Tests\Fixtures\Civility'); |
| 13 | + |
| 14 | + $this->assertInstanceOf('Byscripts\StaticEntity\Tests\Fixtures\Civility', $civility); |
| 15 | + $this->assertEquals('Mister', $civility->getName()); |
| 16 | + $this->assertEquals('mr', $civility->getId()); |
| 17 | + $this->assertEquals('Mr', $civility->getShortName()); |
| 18 | + } |
| 19 | + |
| 20 | + public function testNotFound() |
| 21 | + { |
| 22 | + $civility = StaticEntity::get('non-existent-id', '\Byscripts\StaticEntity\Tests\Fixtures\Civility'); |
| 23 | + |
| 24 | + $this->assertNull($civility); |
| 25 | + } |
| 26 | + |
| 27 | + public function testSameInstances() |
| 28 | + { |
| 29 | + $civility1 = StaticEntity::get('mr', '\Byscripts\StaticEntity\Tests\Fixtures\Civility'); |
| 30 | + $civility2 = StaticEntity::get('mr', '\Byscripts\StaticEntity\Tests\Fixtures\Civility'); |
| 31 | + |
| 32 | + $this->assertSame($civility1, $civility2); |
| 33 | + } |
| 34 | + |
| 35 | + /** |
| 36 | + * @expectedException \Exception |
| 37 | + * @expectedExceptionMessage not exists |
| 38 | + */ |
| 39 | + public function testNotExists() |
| 40 | + { |
| 41 | + StaticEntity::get('mr', 'This\Class\Does\Not\Exists'); |
| 42 | + } |
| 43 | + |
| 44 | + /** |
| 45 | + * @expectedException \Exception |
| 46 | + * @expectedExceptionMessage must extends StaticEntity |
| 47 | + */ |
| 48 | + public function testNotExtends() |
| 49 | + { |
| 50 | + StaticEntity::get('foo', 'Byscripts\StaticEntity\Tests\Fixtures\NotExtends'); |
| 51 | + } |
| 52 | + |
| 53 | + /** |
| 54 | + * @expectedException \Exception |
| 55 | + * @expectedExceptionMessage must be an array |
| 56 | + */ |
| 57 | + public function testInvalidDataSet() |
| 58 | + { |
| 59 | + StaticEntity::get('foo', '\Byscripts\StaticEntity\Tests\Fixtures\InvalidDataSet'); |
| 60 | + } |
| 61 | + |
| 62 | + /** |
| 63 | + * @expectedException \Exception |
| 64 | + * @expectedExceptionMessage Data at index |
| 65 | + */ |
| 66 | + public function testInvalidData() |
| 67 | + { |
| 68 | + StaticEntity::get('foo', '\Byscripts\StaticEntity\Tests\Fixtures\InvalidData'); |
| 69 | + } |
| 70 | + |
| 71 | + /** |
| 72 | + * @expectedException \Exception |
| 73 | + * @expectedExceptionMessage not exists |
| 74 | + */ |
| 75 | + public function testMissingProperty() |
| 76 | + { |
| 77 | + StaticEntity::get('foo', '\Byscripts\StaticEntity\Tests\Fixtures\MissingProperty'); |
| 78 | + } |
| 79 | + |
| 80 | + /** |
| 81 | + * @expectedException \Exception |
| 82 | + * @expectedExceptionMessage $class cannot be null |
| 83 | + */ |
| 84 | + public function testNoClass() |
| 85 | + { |
| 86 | + StaticEntity::get('foo'); |
| 87 | + } |
| 88 | + |
| 89 | + public function testExists() |
| 90 | + { |
| 91 | + $this->assertTrue( |
| 92 | + StaticEntity::exists('mr', '\Byscripts\StaticEntity\Tests\Fixtures\Civility') |
| 93 | + ); |
| 94 | + |
| 95 | + $this->assertFalse( |
| 96 | + StaticEntity::exists('non-existent-id', '\Byscripts\StaticEntity\Tests\Fixtures\Civility') |
| 97 | + ); |
| 98 | + } |
| 99 | + |
| 100 | + public function testToId() |
| 101 | + { |
| 102 | + /** @var $civility \Byscripts\StaticEntity\Tests\Fixtures\Civility */ |
| 103 | + $civility = StaticEntity::get('mr', '\Byscripts\StaticEntity\Tests\Fixtures\Civility'); |
| 104 | + |
| 105 | + $this->assertEquals('mr', StaticEntity::toId($civility, '\Byscripts\StaticEntity\Tests\Fixtures\Civility')); |
| 106 | + $this->assertEquals('mr', StaticEntity::toId('mr', '\Byscripts\StaticEntity\Tests\Fixtures\Civility')); |
| 107 | + } |
| 108 | + |
| 109 | + /** |
| 110 | + * @expectedException \Exception |
| 111 | + * @expectedExceptionMessage Invalid parameter |
| 112 | + */ |
| 113 | + public function testBadToId() |
| 114 | + { |
| 115 | + StaticEntity::toId('non-existent-id', '\Byscripts\StaticEntity\Tests\Fixtures\Civility'); |
| 116 | + } |
| 117 | +} |
0 commit comments