Tests for nullable User#getName().

This commit is contained in:
Alexey Skobkin 2017-01-12 21:49:38 +03:00
parent 45c3a0d9c9
commit aebc31a0fe
3 changed files with 7 additions and 3 deletions

View file

@ -19,7 +19,7 @@ class LoadUserData extends AbstractFixture implements OrderedFixtureInterface
// 99996 // 99996
['login' => 'testuser4', 'name' => 'Test User 4'], ['login' => 'testuser4', 'name' => 'Test User 4'],
//99995 //99995
['login' => 'testuser5', 'name' => 'Test User 5'], ['login' => 'testuser5', 'name' => null],
]; ];
public function load(ObjectManager $om) public function load(ObjectManager $om)

View file

@ -32,7 +32,7 @@ class User
private $login; private $login;
/** /**
* @var string * @var string|null
* *
* @ORM\Column(name="name", type="string", length=255, nullable=true) * @ORM\Column(name="name", type="string", length=255, nullable=true)
*/ */
@ -135,6 +135,9 @@ class User
return $this; return $this;
} }
/**
* @return string|null
*/
public function getName() public function getName()
{ {
return $this->name; return $this->name;

View file

@ -81,6 +81,7 @@ class MainControllerTest extends WebTestCase
public function testAjaxUserAutoComplete() public function testAjaxUserAutoComplete()
{ {
$client = static::createClient(); $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'); $client->request('GET', '/ajax/users/search/testuser');
$this->assertTrue($client->getResponse()->headers->contains('Content-Type', 'application/json'), 'Response has "Content-Type" = "application/json"'); $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->assertNotNull($data, 'JSON data successfully decoded and not empty');
$this->assertTrue(is_array($data), 'JSON data is array'); $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; return $data;
} }