From f76155909394d5c8777a51b41431eaee63f0cb8a Mon Sep 17 00:00:00 2001 From: jobrios Date: Sat, 5 Jul 2014 21:10:59 -0400 Subject: [PATCH 1/4] Unit Test Fix: testing date formats Fixes date tests in tests/FactoryMuffTest.php. Checks that generated date attribute has the specified format --- tests/FactoryMuffTest.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/FactoryMuffTest.php b/tests/FactoryMuffTest.php index f421824..3fd0c04 100644 --- a/tests/FactoryMuffTest.php +++ b/tests/FactoryMuffTest.php @@ -11,7 +11,7 @@ public function setUp() $this->factory = new FactoryMuff(); } - public function test_defauling_to_faker() + public function test_defaulting_to_faker() { $obj = $this->factory->create('SampleModelB'); $this->assertInternalType('array', $obj->card); @@ -34,26 +34,26 @@ public function test_should_get_attributes_for() public function test_date_kind() { - $this->markTestSkipped('Need to check the date format is correct, no the exact date (it is random now)'); - + $format = 'Y-m-d'; $this->factory->define('SampleModelA', array( - 'created' => 'date|Ymd', + 'created' => 'date|' . $format, )); $obj = $this->factory->create('SampleModelA'); - $this->assertEquals($obj->created, date('Ymd')); + $dateTime = \DateTime::createFromFormat($format, $obj->created); + $this->assertEquals($obj->created, $dateTime->format($format)); } public function test_date_kind_with_date() { - $this->markTestSkipped('Need to check the date format is correct, no the exact date (it is random now)'); - + $format = 'Ymd h:s'; $this->factory->define('SampleModelA', array( - 'created' => 'date|Ymd h:s', + 'created' => 'date|' . $format, )); $obj = $this->factory->create('SampleModelA'); - $this->assertEquals($obj->created, date('Ymd h:s')); + $dateTime = \DateTime::createFromFormat($format, $obj->created); + $this->assertEquals($obj->created, $dateTime->format($format)); } public function test_integer() From 1ff2b8153a0a28a25381babd3804660fcb2c5419 Mon Sep 17 00:00:00 2001 From: jobrios Date: Sat, 5 Jul 2014 22:13:02 -0400 Subject: [PATCH 2/4] Unit Test Fix: testing date formats Fixes date tests in tests/FactoryMuffTest.php. Checks that generated date attribute has the specified format. Replaces previous 2 test methods with 1. --- tests/FactoryMuffTest.php | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/tests/FactoryMuffTest.php b/tests/FactoryMuffTest.php index 3fd0c04..079700c 100644 --- a/tests/FactoryMuffTest.php +++ b/tests/FactoryMuffTest.php @@ -34,26 +34,20 @@ public function test_should_get_attributes_for() public function test_date_kind() { - $format = 'Y-m-d'; - $this->factory->define('SampleModelA', array( - 'created' => 'date|' . $format, - )); - - $obj = $this->factory->create('SampleModelA'); - $dateTime = \DateTime::createFromFormat($format, $obj->created); - $this->assertEquals($obj->created, $dateTime->format($format)); - } - - public function test_date_kind_with_date() - { - $format = 'Ymd h:s'; - $this->factory->define('SampleModelA', array( - 'created' => 'date|' . $format, - )); - - $obj = $this->factory->create('SampleModelA'); - $dateTime = \DateTime::createFromFormat($format, $obj->created); - $this->assertEquals($obj->created, $dateTime->format($format)); + $formats = array( + 'Y-m-d', 'Ymd h:s', 'F d Y h:mA', + 'l F j Y', 'G:i:s e', 'D g d-m-y' + ); + + for ($i = 0; $i < count($formats); $i++) { + $this->factory->define('SampleModelA', array( + 'created' => 'date|' . $formats[$i], + )); + + $obj = $this->factory->create('SampleModelA'); + $dateTime = \DateTime::createFromFormat($formats[$i], $obj->created); + $this->assertEquals($obj->created, $dateTime->format($formats[$i])); + } } public function test_integer() From 1883508579de5dfce8714456911fd63f790b1c72 Mon Sep 17 00:00:00 2001 From: jobrios Date: Sat, 5 Jul 2014 22:34:06 -0400 Subject: [PATCH 3/4] Unit Test Fix: testing date formats Fixes date tests in tests/FactoryMuffTest.php. Applied detab. --- tests/FactoryMuffTest.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/FactoryMuffTest.php b/tests/FactoryMuffTest.php index 079700c..35eaa5e 100644 --- a/tests/FactoryMuffTest.php +++ b/tests/FactoryMuffTest.php @@ -40,13 +40,13 @@ public function test_date_kind() ); for ($i = 0; $i < count($formats); $i++) { - $this->factory->define('SampleModelA', array( - 'created' => 'date|' . $formats[$i], - )); + $this->factory->define('SampleModelA', array( + 'created' => 'date|' . $formats[$i], + )); - $obj = $this->factory->create('SampleModelA'); - $dateTime = \DateTime::createFromFormat($formats[$i], $obj->created); - $this->assertEquals($obj->created, $dateTime->format($formats[$i])); + $obj = $this->factory->create('SampleModelA'); + $dateTime = \DateTime::createFromFormat($formats[$i], $obj->created); + $this->assertEquals($obj->created, $dateTime->format($formats[$i])); } } From 8f23319933d5ca1c81ee7cd314ff62a8d96b12e5 Mon Sep 17 00:00:00 2001 From: jobrios Date: Sat, 5 Jul 2014 23:46:59 -0400 Subject: [PATCH 4/4] Unit Test Fix: testing date formats Fixes date tests in tests/FactoryMuffTest.php. Removed for loop. --- tests/FactoryMuffTest.php | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/tests/FactoryMuffTest.php b/tests/FactoryMuffTest.php index 35eaa5e..0344088 100644 --- a/tests/FactoryMuffTest.php +++ b/tests/FactoryMuffTest.php @@ -34,20 +34,15 @@ public function test_should_get_attributes_for() public function test_date_kind() { - $formats = array( - 'Y-m-d', 'Ymd h:s', 'F d Y h:mA', - 'l F j Y', 'G:i:s e', 'D g d-m-y' - ); + $format = 'Y-m-d'; - for ($i = 0; $i < count($formats); $i++) { - $this->factory->define('SampleModelA', array( - 'created' => 'date|' . $formats[$i], - )); - - $obj = $this->factory->create('SampleModelA'); - $dateTime = \DateTime::createFromFormat($formats[$i], $obj->created); - $this->assertEquals($obj->created, $dateTime->format($formats[$i])); - } + $this->factory->define('SampleModelA', array( + 'created' => 'date|' . $format, + )); + + $obj = $this->factory->create('SampleModelA'); + $dateTime = \DateTime::createFromFormat($format, $obj->created); + $this->assertEquals($obj->created, $dateTime->format($format)); } public function test_integer()