Fix the failing unit tests
refactor the codestyle for the tests we wanted to keep
This commit is contained in:
@@ -1,40 +1,44 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @group Lib
|
||||
* @group Unit
|
||||
*/
|
||||
namespace Tests\Unit\Memory;
|
||||
|
||||
use App\Libraries\abcParse\Person;
|
||||
use \Codeception\TestCase\Test;
|
||||
use Codeception\TestCase\Test;
|
||||
use XaiCorp\AbcParser\Models\Memory\Person;
|
||||
|
||||
class PersonTest extends Test
|
||||
{
|
||||
private $_person;
|
||||
private $person;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->_person = new Person();
|
||||
$this->person = new Person();
|
||||
}
|
||||
|
||||
/**
|
||||
* test the model contains the correct attributes
|
||||
*/
|
||||
public function test_model_definition()
|
||||
public function testModelDefinition()
|
||||
{
|
||||
$this->assertClassHasAttribute('person_id', Person::class);
|
||||
$this->assertClassHasAttribute('name', Person::class);
|
||||
$this->assertClassHasAttribute('email', Person::class);
|
||||
}
|
||||
|
||||
public function test_construct()
|
||||
public function testConstruct()
|
||||
{
|
||||
$params = array('person_id' => 5);
|
||||
$this->_person = new Person($params);
|
||||
$params = ['person_id' => 5];
|
||||
$this->person = new Person($params);
|
||||
|
||||
$this->assertEquals(5, $this->_person->get('person_id'));
|
||||
$this->assertEquals(5, $this->person->get('person_id'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerSet
|
||||
*/
|
||||
public function testMagicSet($property, $value, $expected)
|
||||
{
|
||||
$this->testSet($property, $value, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* test the set property method
|
||||
@@ -43,74 +47,65 @@ class PersonTest extends Test
|
||||
* @param (mixed) value to set
|
||||
* @param (Boolean) expected value for return value of set method
|
||||
*
|
||||
* @dataProvider provider_set
|
||||
* @dataProvider providerSet
|
||||
*/
|
||||
public function test_set($property, $value, $expected)
|
||||
public function testSet($property, $value, $expected)
|
||||
{
|
||||
$success = $this->_person->set($property, $value);
|
||||
$success = $this->person->set($property, $value);
|
||||
$this->assertEquals($expected, $success);
|
||||
if($success)
|
||||
{
|
||||
$this->assertEquals($value, $this->_person->get($property));
|
||||
if ($success) {
|
||||
$this->assertEquals($value, $this->person->get($property));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provider_set
|
||||
*/
|
||||
public function test_magic_set($property, $value, $expected)
|
||||
public function providerSet()
|
||||
{
|
||||
$this->test_set($property, $value, $expected);
|
||||
}
|
||||
|
||||
public function provider_set()
|
||||
{
|
||||
return array(
|
||||
array('Y', 'anything', FALSE),
|
||||
array('person_id', 'not', FALSE),
|
||||
array('person_id', 11, TRUE),
|
||||
array('person_id', '11', TRUE),
|
||||
array('name', null, FALSE),
|
||||
array('name', 1, FALSE),
|
||||
array('name', 'anything', TRUE),
|
||||
array('email', 'anything', FALSE),
|
||||
array('email', 1, FALSE),
|
||||
array('email', 'mail@example.com', TRUE),
|
||||
);
|
||||
return [
|
||||
['Y', 'anything', false],
|
||||
['person_id', 'not', false],
|
||||
['person_id', 11, true],
|
||||
['person_id', '11', true],
|
||||
['name', null, false],
|
||||
['name', 1, false],
|
||||
['name', 'anything', true],
|
||||
['email', 'anything', false],
|
||||
['email', 1, false],
|
||||
['email', 'mail@example.com', true],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provider_person_get
|
||||
* @dataProvider providerPersonGet
|
||||
*/
|
||||
public function test_person_get($key, $expected)
|
||||
public function testPersonGet($key, $expected)
|
||||
{
|
||||
$result = $this->_person->set($key, $expected);
|
||||
$result = $this->_person->get($key);
|
||||
$result = $this->person->set($key, $expected);
|
||||
$result = $this->person->get($key);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function provider_person_get()
|
||||
public function providerPersonGet()
|
||||
{
|
||||
return array(
|
||||
array('', FALSE),
|
||||
array('me', FALSE),
|
||||
array(array('of','me'), FALSE),
|
||||
array(new Person(), FALSE),
|
||||
array('name', 'Richard Morgan'),
|
||||
array('email', 'r_morgan@sympatico.ca'),
|
||||
array('person_id', 0)
|
||||
);
|
||||
return [
|
||||
['', false],
|
||||
['me', false],
|
||||
[['of', 'me'], false],
|
||||
[new Person(), false],
|
||||
['name', 'Richard Morgan'],
|
||||
['email', 'r_morgan@sympatico.ca'],
|
||||
['person_id', 0],
|
||||
];
|
||||
}
|
||||
|
||||
public function test_is_changed()
|
||||
public function testIsChanged()
|
||||
{
|
||||
$person = new Person(array('name'=>'Richard Morgan'));
|
||||
$person = new Person(['name' => 'Richard Morgan']);
|
||||
|
||||
$this->assertInstanceOf(Person::class, $person);
|
||||
|
||||
$this->assertFalse($person->is_changed(), 'after load should be no changes');
|
||||
|
||||
$person->set('name','Richard Armitage');
|
||||
$person->set('name', 'Richard Armitage');
|
||||
$this->assertTrue($person->is_changed(), 'updating the name changes the data');
|
||||
}
|
||||
|
||||
@@ -122,23 +117,18 @@ class PersonTest extends Test
|
||||
* @param (array) $params list of properties to set on the objects
|
||||
* @param (boolean) $expected result of running equals
|
||||
*
|
||||
* @dataProvider provider_equals
|
||||
* @dataProvider providerEquals
|
||||
*/
|
||||
public function test_equals($params)
|
||||
public function testEquals($params)
|
||||
{
|
||||
// $this->markTestIncomplete();
|
||||
|
||||
$ob1 = new Person();
|
||||
$ob2 = new Person();
|
||||
|
||||
foreach($params as $key => $val)
|
||||
{
|
||||
if(is_array($ob1->get($key)))
|
||||
{
|
||||
foreach ($params as $key => $val) {
|
||||
if (is_array($ob1->get($key))) {
|
||||
$ob1->append($key, $val);
|
||||
$ob2->append($key, $val);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$ob1->set($key, $val);
|
||||
$ob2->set($key, $val);
|
||||
}
|
||||
@@ -146,6 +136,7 @@ class PersonTest extends Test
|
||||
|
||||
$this->assertTrue(Person::equals($ob1, $ob2));
|
||||
}
|
||||
|
||||
/**
|
||||
* test the static function equals
|
||||
* returns true if the data properties of 2 Person objects
|
||||
@@ -154,36 +145,32 @@ class PersonTest extends Test
|
||||
* @param (array) $params list of properties to set on the objects
|
||||
* @param (boolean) $expected result of running equals
|
||||
*
|
||||
* @dataProvider provider_equals
|
||||
* @dataProvider providerEquals
|
||||
*/
|
||||
public function test_equals_fails($params)
|
||||
public function testEqualsFails($params)
|
||||
{
|
||||
$ob1 = new Person();
|
||||
$ob2 = new Person();
|
||||
|
||||
foreach($params as $key => $val)
|
||||
{
|
||||
if(is_array($ob1->get($key)))
|
||||
{
|
||||
foreach ($params as $key => $val) {
|
||||
if (is_array($ob1->get($key))) {
|
||||
$ob1->append($key, $val);
|
||||
$ob2->append($key, $val." hello");
|
||||
}
|
||||
else {
|
||||
$ob2->append($key, $val . " hello");
|
||||
} else {
|
||||
$ob1->set($key, $val);
|
||||
$ob2->set($key, $val+1);
|
||||
$ob2->set($key, $val + 1);
|
||||
}
|
||||
}
|
||||
// print_r($ob1); print_r($ob2); die;
|
||||
$this->assertFalse(Person::equals($ob1, $ob2));
|
||||
}
|
||||
public function provider_equals()
|
||||
|
||||
public function providerEquals()
|
||||
{
|
||||
return array(
|
||||
return [
|
||||
// array( array('person_id'=>'2') ),
|
||||
array( array('name'=>'a title') ),
|
||||
array( array('email'=>'mail@example.com') ),
|
||||
);
|
||||
[['name' => 'a title']],
|
||||
[['email' => 'mail@example.com']],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user