From b2d940c8140a23f215b70641bf55159d7ebf51d6 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Thu, 18 Sep 2014 19:08:04 +0100 Subject: [PATCH] Test improvements --- phpunit.xml.dist | 2 +- tests/CustomisationTest.php | 8 +++--- tests/DefinitionTest.php | 24 ++++++++-------- tests/FactoryMuffinTest.php | 24 ++++++++-------- tests/SaveAndDeleteTest.php | 56 ++++++++++++++++++------------------- 5 files changed, 57 insertions(+), 57 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 53baf2c..1d8b538 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -11,7 +11,7 @@ stopOnFailure="false" syntaxCheck="true" strict="true" - verbose="true"> + verbose="true" > diff --git a/tests/CustomisationTest.php b/tests/CustomisationTest.php index 16544b7..507f591 100644 --- a/tests/CustomisationTest.php +++ b/tests/CustomisationTest.php @@ -49,8 +49,8 @@ public function testCustomSaverFail() try { FactoryMuffin::create($model = 'SaverAndDeleterCustomisationModelStub'); } catch (SaveFailedException $e) { - $this->assertEquals("We could not save the model of type: '$model'.", $e->getMessage()); - $this->assertEquals($model, $e->getModel()); + $this->assertSame("We could not save the model of type: '$model'.", $e->getMessage()); + $this->assertSame($model, $e->getModel()); $this->assertNull($e->getErrors()); $this->reload(); throw $e; @@ -77,8 +77,8 @@ public function testCustomDeleterFail() FactoryMuffin::deleteSaved(); } catch (DeletingFailedException $e) { $exceptions = $e->getExceptions(); - $this->assertEquals("We encountered 1 problem(s) while trying to delete the saved models.", $e->getMessage()); - $this->assertEquals("We could not delete the model of type: '$model'.", $exceptions[0]->getMessage()); + $this->assertSame("We encountered 1 problem(s) while trying to delete the saved models.", $e->getMessage()); + $this->assertSame("We could not delete the model of type: '$model'.", $exceptions[0]->getMessage()); $this->reload(); throw $e; } diff --git a/tests/DefinitionTest.php b/tests/DefinitionTest.php index 525474f..720e64d 100644 --- a/tests/DefinitionTest.php +++ b/tests/DefinitionTest.php @@ -42,8 +42,8 @@ public function testModelNotFound() try { FactoryMuffin::create($model = 'NotAClass'); } catch (ModelNotFoundException $e) { - $this->assertEquals("No class was defined for the model of type: '$model'.", $e->getMessage()); - $this->assertEquals($model, $e->getModel()); + $this->assertSame("No class was defined for the model of type: '$model'.", $e->getMessage()); + $this->assertSame($model, $e->getModel()); throw $e; } } @@ -68,7 +68,7 @@ public function testGroupDefineOverwrite() $this->assertInternalType('string', $user->address); $this->assertInternalType('string', $user->name); $this->assertNotInternalType('boolean', $user->active); - $this->assertEquals('false', $user->active); + $this->assertSame('false', $user->active); $this->assertContains('@', $user->email); } @@ -77,7 +77,7 @@ public function testGroupCallback() $user = FactoryMuffin::create('callbackgroup:UserModelStub'); $this->assertInstanceOf('UserModelStub', $user); - $this->assertEquals('bar', $user->test); + $this->assertSame('bar', $user->test); $this->assertInternalType('string', $user->name); $this->assertInternalType('boolean', $user->active); $this->assertContains('@', $user->email); @@ -91,8 +91,8 @@ public function testShouldThrowExceptionWhenLoadingANonExistentGroup() try { FactoryMuffin::create('error:UserModelStub'); } catch (NoDefinedFactoryException $e) { - $this->assertEquals("No factory definition(s) were defined for the model of type: 'error:UserModelStub'.", $e->getMessage()); - $this->assertEquals('error:UserModelStub', $e->getModel()); + $this->assertSame("No factory definition(s) were defined for the model of type: 'error:UserModelStub'.", $e->getMessage()); + $this->assertSame('error:UserModelStub', $e->getModel()); throw $e; } } @@ -105,8 +105,8 @@ public function testGroupDefineNoBaseModel() try { FactoryMuffin::create('foo:DogModelStub'); } catch (NoDefinedFactoryException $e) { - $this->assertEquals("No factory definition(s) were defined for the model of type: 'DogModelStub'.", $e->getMessage()); - $this->assertEquals('DogModelStub', $e->getModel()); + $this->assertSame("No factory definition(s) were defined for the model of type: 'DogModelStub'.", $e->getMessage()); + $this->assertSame('DogModelStub', $e->getModel()); throw $e; } } @@ -144,14 +144,14 @@ public function testInstance() public function testInstanceCallback() { $obj = FactoryMuffin::instance('ExampleCallbackStub'); - $this->assertEquals('yaycalled', $obj->callback); + $this->assertSame('yaycalled', $obj->callback); $this->assertFalse($obj->saved); } public function testCreateCallback() { $obj = FactoryMuffin::create('AnotherCallbackStub'); - $this->assertEquals('hello there', $obj->foo); + $this->assertSame('hello there', $obj->foo); $this->assertTrue($obj->saved); } @@ -185,8 +185,8 @@ public function testShouldThrowExceptionWhenLoadingANonExistentDirectory() try { FactoryMuffin::loadFactories($path = __DIR__.'/thisdirectorydoesntexist'); } catch (DirectoryNotFoundException $e) { - $this->assertEquals("The directory '$path' was not found.", $e->getMessage()); - $this->assertEquals($path, $e->getPath()); + $this->assertSame("The directory '$path' was not found.", $e->getMessage()); + $this->assertSame($path, $e->getPath()); throw $e; } } diff --git a/tests/FactoryMuffinTest.php b/tests/FactoryMuffinTest.php index 92601d3..2e9f9a1 100644 --- a/tests/FactoryMuffinTest.php +++ b/tests/FactoryMuffinTest.php @@ -18,7 +18,7 @@ public function testDefaultingToFaker() $this->assertArrayHasKey('name', $obj->card); $this->assertArrayHasKey('expirationDate', $obj->card); - $this->assertEquals('http://lorempixel.com/400/600/', $obj->image); + $this->assertSame('http://lorempixel.com/400/600/', $obj->image); $this->assertNotEquals('unique::text', $obj->unique_text); $this->assertNotEquals('optional::text', $obj->optional_text); } @@ -45,9 +45,9 @@ public function testGetIds() { $obj = FactoryMuffin::instance('IdTestModelStub'); - $this->assertEquals(1, $obj->modelGetKey); - $this->assertEquals(1, $obj->modelPk); - $this->assertEquals(1, $obj->model_id); + $this->assertSame(1, $obj->modelGetKey); + $this->assertSame(1, $obj->modelPk); + $this->assertSame(1, $obj->model_id); $this->assertNull($obj->model_null); } @@ -57,7 +57,7 @@ public function testShouldMakeSimpleCalls() $expected = gmdate('Y-m-d', strtotime('+40 days')); - $this->assertEquals($expected, $obj->future); + $this->assertSame($expected, $obj->future); } public function testShouldPassSimpleArgumentsToCalls() @@ -105,8 +105,8 @@ public function testShouldThrowExceptionWhenNoDefinedFactoryException() try { FactoryMuffin::instance($model = 'ModelWithNoFactoryClassStub'); } catch (NoDefinedFactoryException $e) { - $this->assertEquals("No factory definition(s) were defined for the model of type: '$model'.", $e->getMessage()); - $this->assertEquals($model, $e->getModel()); + $this->assertSame("No factory definition(s) were defined for the model of type: '$model'.", $e->getMessage()); + $this->assertSame($model, $e->getModel()); throw $e; } } @@ -114,14 +114,14 @@ public function testShouldThrowExceptionWhenNoDefinedFactoryException() public function testShouldAcceptClosureAsAttributeFactory() { $obj = FactoryMuffin::instance('MainModelStub'); - $this->assertEquals('just a string', $obj->text_closure); + $this->assertSame('just a string', $obj->text_closure); } public function testCanCreateFromStaticMethod() { $obj = FactoryMuffin::instance('ModelWithStaticMethodFactory'); - $this->assertEquals('just a string', $obj->string); + $this->assertSame('just a string', $obj->string); $this->assertInstanceOf('ModelWithStaticMethodFactory', $obj->data['object']); $this->assertFalse($obj->data['saved']); } @@ -134,9 +134,9 @@ public function testThrowExceptionWhenInvalidStaticMethod() try { FactoryMuffin::create($model = 'ModelWithMissingStaticMethod'); } catch (MethodNotFoundException $e) { - $this->assertEquals("The static method 'doesNotExist' was not found on the model of type: '$model'.", $e->getMessage()); - $this->assertEquals($model, $e->getModel()); - $this->assertEquals('doesNotExist', $e->getMethod()); + $this->assertSame("The static method 'doesNotExist' was not found on the model of type: '$model'.", $e->getMessage()); + $this->assertSame($model, $e->getModel()); + $this->assertSame('doesNotExist', $e->getMethod()); throw $e; } } diff --git a/tests/SaveAndDeleteTest.php b/tests/SaveAndDeleteTest.php index dd73ccc..3e46f9c 100644 --- a/tests/SaveAndDeleteTest.php +++ b/tests/SaveAndDeleteTest.php @@ -41,9 +41,9 @@ public function testShouldThrowExceptionAfterSaveMethodRename() try { FactoryMuffin::create($model = 'ModelThatWillSaveStub'); } catch (SaveMethodNotFoundException $e) { - $this->assertEquals("The save method 'foo' was not found on the model of type: '$model'.", $e->getMessage()); - $this->assertEquals($model, $e->getModel()); - $this->assertEquals('foo', $e->getMethod()); + $this->assertSame("The save method 'foo' was not found on the model of type: '$model'.", $e->getMessage()); + $this->assertSame($model, $e->getModel()); + $this->assertSame('foo', $e->getMethod()); $this->assertInstanceOf($model, $e->getObject()); $this->reload(); throw $e; @@ -64,10 +64,10 @@ public function testShouldThrowExceptionAfterDeleteMethodRename() FactoryMuffin::deleteSaved(); } catch (DeletingFailedException $e) { $exceptions = $e->getExceptions(); - $this->assertEquals("We encountered 1 problem(s) while trying to delete the saved models.", $e->getMessage()); - $this->assertEquals("The delete method 'bar' was not found on the model of type: '$model'.", $exceptions[0]->getMessage()); - $this->assertEquals($model, $exceptions[0]->getModel()); - $this->assertEquals('bar', $exceptions[0]->getMethod()); + $this->assertSame("We encountered 1 problem(s) while trying to delete the saved models.", $e->getMessage()); + $this->assertSame("The delete method 'bar' was not found on the model of type: '$model'.", $exceptions[0]->getMessage()); + $this->assertSame($model, $exceptions[0]->getModel()); + $this->assertSame('bar', $exceptions[0]->getMethod()); $this->assertInstanceOf($model, $exceptions[0]->getObject()); $this->reload(); throw $e; @@ -84,8 +84,8 @@ public function testShouldThrowExceptionOnModelSaveFailure() try { FactoryMuffin::create($model = 'ModelThatFailsToSaveStub'); } catch (SaveFailedException $e) { - $this->assertEquals("We could not save the model of type: '$model'.", $e->getMessage()); - $this->assertEquals($model, $e->getModel()); + $this->assertSame("We could not save the model of type: '$model'.", $e->getMessage()); + $this->assertSame($model, $e->getModel()); $this->assertNull($e->getErrors()); throw $e; } @@ -101,8 +101,8 @@ public function testShouldThrowExceptionOnModelDeleteFailure() FactoryMuffin::deleteSaved(); } catch (DeletingFailedException $e) { $exceptions = $e->getExceptions(); - $this->assertEquals("We encountered 1 problem(s) while trying to delete the saved models.", $e->getMessage()); - $this->assertEquals("We could not delete the model of type: '$model'.", $exceptions[0]->getMessage()); + $this->assertSame("We encountered 1 problem(s) while trying to delete the saved models.", $e->getMessage()); + $this->assertSame("We could not delete the model of type: '$model'.", $exceptions[0]->getMessage()); throw $e; } } @@ -117,8 +117,8 @@ public function testShouldAlsoThrowExceptionOnModelDeleteFailure() FactoryMuffin::deleteSaved(); } catch (DeletingFailedException $e) { $exceptions = $e->getExceptions(); - $this->assertEquals("We encountered 1 problem(s) while trying to delete the saved models.", $e->getMessage()); - $this->assertEquals("OH NOES!", $exceptions[0]->getMessage()); + $this->assertSame("We encountered 1 problem(s) while trying to delete the saved models.", $e->getMessage()); + $this->assertSame("OH NOES!", $exceptions[0]->getMessage()); throw $e; } } @@ -131,9 +131,9 @@ public function testShouldThrowExceptionWithoutSaveMethod() try { FactoryMuffin::create($model = 'ModelWithNoSaveMethodStub'); } catch (SaveMethodNotFoundException $e) { - $this->assertEquals("The save method 'save' was not found on the model of type: '$model'.", $e->getMessage()); - $this->assertEquals($model, $e->getModel()); - $this->assertEquals('save', $e->getMethod()); + $this->assertSame("The save method 'save' was not found on the model of type: '$model'.", $e->getMessage()); + $this->assertSame($model, $e->getModel()); + $this->assertSame('save', $e->getMethod()); $this->assertInstanceOf($model, $e->getObject()); throw $e; } @@ -149,10 +149,10 @@ public function testShouldThrowExceptionWithoutDeleteMethod() FactoryMuffin::deleteSaved(); } catch (DeletingFailedException $e) { $exceptions = $e->getExceptions(); - $this->assertEquals("We encountered 1 problem(s) while trying to delete the saved models.", $e->getMessage()); - $this->assertEquals("The delete method 'delete' was not found on the model of type: '$model'.", $exceptions[0]->getMessage()); - $this->assertEquals($model, $exceptions[0]->getModel()); - $this->assertEquals('delete', $exceptions[0]->getMethod()); + $this->assertSame("We encountered 1 problem(s) while trying to delete the saved models.", $e->getMessage()); + $this->assertSame("The delete method 'delete' was not found on the model of type: '$model'.", $exceptions[0]->getMessage()); + $this->assertSame($model, $exceptions[0]->getModel()); + $this->assertSame('delete', $exceptions[0]->getMethod()); $this->assertInstanceOf($model, $exceptions[0]->getObject()); throw $e; } @@ -166,9 +166,9 @@ public function testShouldThrowExceptionWithValidationErrors() try { FactoryMuffin::create($model = 'ModelWithValidationErrorsStub'); } catch (SaveFailedException $e) { - $this->assertEquals("Failed to save. We could not save the model of type: '$model'.", $e->getMessage()); - $this->assertEquals($model, $e->getModel()); - $this->assertEquals('Failed to save.', $e->getErrors()); + $this->assertSame("Failed to save. We could not save the model of type: '$model'.", $e->getMessage()); + $this->assertSame($model, $e->getModel()); + $this->assertSame('Failed to save.', $e->getErrors()); throw $e; } } @@ -184,11 +184,11 @@ public function testShouldThrowMultipleDeletionExceptions() FactoryMuffin::deleteSaved(); } catch (DeletingFailedException $e) { $exceptions = $e->getExceptions(); - $this->assertEquals("We encountered 2 problem(s) while trying to delete the saved models.", $e->getMessage()); - $this->assertEquals("OH NOES!", $exceptions[0]->getMessage()); - $this->assertEquals("The delete method 'delete' was not found on the model of type: '$model'.", $exceptions[1]->getMessage()); - $this->assertEquals($model, $exceptions[1]->getModel()); - $this->assertEquals('delete', $exceptions[1]->getMethod()); + $this->assertSame("We encountered 2 problem(s) while trying to delete the saved models.", $e->getMessage()); + $this->assertSame("OH NOES!", $exceptions[0]->getMessage()); + $this->assertSame("The delete method 'delete' was not found on the model of type: '$model'.", $exceptions[1]->getMessage()); + $this->assertSame($model, $exceptions[1]->getModel()); + $this->assertSame('delete', $exceptions[1]->getMethod()); $this->assertInstanceOf($model, $exceptions[1]->getObject()); $this->assertInternalType('array', $e->getExceptions()); $this->assertCount(2, $e->getExceptions());