diff --git a/src/Skobkin/Bundle/PointToolsBundle/DataFixtures/ORM/LoadUserData.php b/src/Skobkin/Bundle/PointToolsBundle/DataFixtures/ORM/LoadUserData.php index e9a4633..a84e9dc 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/DataFixtures/ORM/LoadUserData.php +++ b/src/Skobkin/Bundle/PointToolsBundle/DataFixtures/ORM/LoadUserData.php @@ -19,7 +19,7 @@ class LoadUserData extends AbstractFixture implements OrderedFixtureInterface // 99996 ['login' => 'testuser4', 'name' => 'Test User 4'], //99995 - ['login' => 'testuser5', 'name' => 'Test User 5'], + ['login' => 'testuser5', 'name' => null], ]; public function load(ObjectManager $om) diff --git a/src/Skobkin/Bundle/PointToolsBundle/Entity/User.php b/src/Skobkin/Bundle/PointToolsBundle/Entity/User.php index 3f23e35..cad66c7 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/Entity/User.php +++ b/src/Skobkin/Bundle/PointToolsBundle/Entity/User.php @@ -32,7 +32,7 @@ class User private $login; /** - * @var string + * @var string|null * * @ORM\Column(name="name", type="string", length=255, nullable=true) */ @@ -135,6 +135,9 @@ class User return $this; } + /** + * @return string|null + */ public function getName() { return $this->name; diff --git a/tests/Skobkin/PointToolsBundle/Controller/MainControllerTest.php b/tests/Skobkin/PointToolsBundle/Controller/MainControllerTest.php index ea76661..d1fb5a0 100644 --- a/tests/Skobkin/PointToolsBundle/Controller/MainControllerTest.php +++ b/tests/Skobkin/PointToolsBundle/Controller/MainControllerTest.php @@ -81,6 +81,7 @@ class MainControllerTest extends WebTestCase public function testAjaxUserAutoComplete() { $client = static::createClient(); + // We need to search all test user with 'testuser5' included which will test the code against null-string problem in User#getName() $client->request('GET', '/ajax/users/search/testuser'); $this->assertTrue($client->getResponse()->headers->contains('Content-Type', 'application/json'), 'Response has "Content-Type" = "application/json"'); @@ -99,7 +100,7 @@ class MainControllerTest extends WebTestCase $this->assertNotNull($data, 'JSON data successfully decoded and not empty'); $this->assertTrue(is_array($data), 'JSON data is array'); - $this->assertGreaterThan(0, count($data), 'Array has at least one element'); + $this->assertCount(5, $data, 'Array has 5 elements'); return $data; }