Skip to content

Commit 91f0adc

Browse files
Merge pull request #327 from GrahamCampbell/2.1-tests
[2.1] More Testing Improvements
2 parents 3d502c5 + b2d940c commit 91f0adc

File tree

5 files changed

+57
-57
lines changed

5 files changed

+57
-57
lines changed

phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
stopOnFailure="false"
1212
syntaxCheck="true"
1313
strict="true"
14-
verbose="true">
14+
verbose="true"
1515
>
1616
<testsuites>
1717
<testsuite name="Factory Muffin Test Suite">

tests/CustomisationTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ public function testCustomSaverFail()
4949
try {
5050
FactoryMuffin::create($model = 'SaverAndDeleterCustomisationModelStub');
5151
} catch (SaveFailedException $e) {
52-
$this->assertEquals("We could not save the model of type: '$model'.", $e->getMessage());
53-
$this->assertEquals($model, $e->getModel());
52+
$this->assertSame("We could not save the model of type: '$model'.", $e->getMessage());
53+
$this->assertSame($model, $e->getModel());
5454
$this->assertNull($e->getErrors());
5555
$this->reload();
5656
throw $e;
@@ -77,8 +77,8 @@ public function testCustomDeleterFail()
7777
FactoryMuffin::deleteSaved();
7878
} catch (DeletingFailedException $e) {
7979
$exceptions = $e->getExceptions();
80-
$this->assertEquals("We encountered 1 problem(s) while trying to delete the saved models.", $e->getMessage());
81-
$this->assertEquals("We could not delete the model of type: '$model'.", $exceptions[0]->getMessage());
80+
$this->assertSame("We encountered 1 problem(s) while trying to delete the saved models.", $e->getMessage());
81+
$this->assertSame("We could not delete the model of type: '$model'.", $exceptions[0]->getMessage());
8282
$this->reload();
8383
throw $e;
8484
}

tests/DefinitionTest.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ public function testModelNotFound()
4242
try {
4343
FactoryMuffin::create($model = 'NotAClass');
4444
} catch (ModelNotFoundException $e) {
45-
$this->assertEquals("No class was defined for the model of type: '$model'.", $e->getMessage());
46-
$this->assertEquals($model, $e->getModel());
45+
$this->assertSame("No class was defined for the model of type: '$model'.", $e->getMessage());
46+
$this->assertSame($model, $e->getModel());
4747
throw $e;
4848
}
4949
}
@@ -68,7 +68,7 @@ public function testGroupDefineOverwrite()
6868
$this->assertInternalType('string', $user->address);
6969
$this->assertInternalType('string', $user->name);
7070
$this->assertNotInternalType('boolean', $user->active);
71-
$this->assertEquals('false', $user->active);
71+
$this->assertSame('false', $user->active);
7272
$this->assertContains('@', $user->email);
7373
}
7474

@@ -77,7 +77,7 @@ public function testGroupCallback()
7777
$user = FactoryMuffin::create('callbackgroup:UserModelStub');
7878

7979
$this->assertInstanceOf('UserModelStub', $user);
80-
$this->assertEquals('bar', $user->test);
80+
$this->assertSame('bar', $user->test);
8181
$this->assertInternalType('string', $user->name);
8282
$this->assertInternalType('boolean', $user->active);
8383
$this->assertContains('@', $user->email);
@@ -91,8 +91,8 @@ public function testShouldThrowExceptionWhenLoadingANonExistentGroup()
9191
try {
9292
FactoryMuffin::create('error:UserModelStub');
9393
} catch (NoDefinedFactoryException $e) {
94-
$this->assertEquals("No factory definition(s) were defined for the model of type: 'error:UserModelStub'.", $e->getMessage());
95-
$this->assertEquals('error:UserModelStub', $e->getModel());
94+
$this->assertSame("No factory definition(s) were defined for the model of type: 'error:UserModelStub'.", $e->getMessage());
95+
$this->assertSame('error:UserModelStub', $e->getModel());
9696
throw $e;
9797
}
9898
}
@@ -105,8 +105,8 @@ public function testGroupDefineNoBaseModel()
105105
try {
106106
FactoryMuffin::create('foo:DogModelStub');
107107
} catch (NoDefinedFactoryException $e) {
108-
$this->assertEquals("No factory definition(s) were defined for the model of type: 'DogModelStub'.", $e->getMessage());
109-
$this->assertEquals('DogModelStub', $e->getModel());
108+
$this->assertSame("No factory definition(s) were defined for the model of type: 'DogModelStub'.", $e->getMessage());
109+
$this->assertSame('DogModelStub', $e->getModel());
110110
throw $e;
111111
}
112112
}
@@ -144,14 +144,14 @@ public function testInstance()
144144
public function testInstanceCallback()
145145
{
146146
$obj = FactoryMuffin::instance('ExampleCallbackStub');
147-
$this->assertEquals('yaycalled', $obj->callback);
147+
$this->assertSame('yaycalled', $obj->callback);
148148
$this->assertFalse($obj->saved);
149149
}
150150

151151
public function testCreateCallback()
152152
{
153153
$obj = FactoryMuffin::create('AnotherCallbackStub');
154-
$this->assertEquals('hello there', $obj->foo);
154+
$this->assertSame('hello there', $obj->foo);
155155
$this->assertTrue($obj->saved);
156156
}
157157

@@ -185,8 +185,8 @@ public function testShouldThrowExceptionWhenLoadingANonExistentDirectory()
185185
try {
186186
FactoryMuffin::loadFactories($path = __DIR__.'/thisdirectorydoesntexist');
187187
} catch (DirectoryNotFoundException $e) {
188-
$this->assertEquals("The directory '$path' was not found.", $e->getMessage());
189-
$this->assertEquals($path, $e->getPath());
188+
$this->assertSame("The directory '$path' was not found.", $e->getMessage());
189+
$this->assertSame($path, $e->getPath());
190190
throw $e;
191191
}
192192
}

tests/FactoryMuffinTest.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public function testDefaultingToFaker()
1818
$this->assertArrayHasKey('name', $obj->card);
1919
$this->assertArrayHasKey('expirationDate', $obj->card);
2020

21-
$this->assertEquals('http://lorempixel.com/400/600/', $obj->image);
21+
$this->assertSame('http://lorempixel.com/400/600/', $obj->image);
2222
$this->assertNotEquals('unique::text', $obj->unique_text);
2323
$this->assertNotEquals('optional::text', $obj->optional_text);
2424
}
@@ -45,9 +45,9 @@ public function testGetIds()
4545
{
4646
$obj = FactoryMuffin::instance('IdTestModelStub');
4747

48-
$this->assertEquals(1, $obj->modelGetKey);
49-
$this->assertEquals(1, $obj->modelPk);
50-
$this->assertEquals(1, $obj->model_id);
48+
$this->assertSame(1, $obj->modelGetKey);
49+
$this->assertSame(1, $obj->modelPk);
50+
$this->assertSame(1, $obj->model_id);
5151
$this->assertNull($obj->model_null);
5252
}
5353

@@ -57,7 +57,7 @@ public function testShouldMakeSimpleCalls()
5757

5858
$expected = gmdate('Y-m-d', strtotime('+40 days'));
5959

60-
$this->assertEquals($expected, $obj->future);
60+
$this->assertSame($expected, $obj->future);
6161
}
6262

6363
public function testShouldPassSimpleArgumentsToCalls()
@@ -105,23 +105,23 @@ public function testShouldThrowExceptionWhenNoDefinedFactoryException()
105105
try {
106106
FactoryMuffin::instance($model = 'ModelWithNoFactoryClassStub');
107107
} catch (NoDefinedFactoryException $e) {
108-
$this->assertEquals("No factory definition(s) were defined for the model of type: '$model'.", $e->getMessage());
109-
$this->assertEquals($model, $e->getModel());
108+
$this->assertSame("No factory definition(s) were defined for the model of type: '$model'.", $e->getMessage());
109+
$this->assertSame($model, $e->getModel());
110110
throw $e;
111111
}
112112
}
113113

114114
public function testShouldAcceptClosureAsAttributeFactory()
115115
{
116116
$obj = FactoryMuffin::instance('MainModelStub');
117-
$this->assertEquals('just a string', $obj->text_closure);
117+
$this->assertSame('just a string', $obj->text_closure);
118118
}
119119

120120
public function testCanCreateFromStaticMethod()
121121
{
122122
$obj = FactoryMuffin::instance('ModelWithStaticMethodFactory');
123123

124-
$this->assertEquals('just a string', $obj->string);
124+
$this->assertSame('just a string', $obj->string);
125125
$this->assertInstanceOf('ModelWithStaticMethodFactory', $obj->data['object']);
126126
$this->assertFalse($obj->data['saved']);
127127
}
@@ -134,9 +134,9 @@ public function testThrowExceptionWhenInvalidStaticMethod()
134134
try {
135135
FactoryMuffin::create($model = 'ModelWithMissingStaticMethod');
136136
} catch (MethodNotFoundException $e) {
137-
$this->assertEquals("The static method 'doesNotExist' was not found on the model of type: '$model'.", $e->getMessage());
138-
$this->assertEquals($model, $e->getModel());
139-
$this->assertEquals('doesNotExist', $e->getMethod());
137+
$this->assertSame("The static method 'doesNotExist' was not found on the model of type: '$model'.", $e->getMessage());
138+
$this->assertSame($model, $e->getModel());
139+
$this->assertSame('doesNotExist', $e->getMethod());
140140
throw $e;
141141
}
142142
}

tests/SaveAndDeleteTest.php

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ public function testShouldThrowExceptionAfterSaveMethodRename()
4141
try {
4242
FactoryMuffin::create($model = 'ModelThatWillSaveStub');
4343
} catch (SaveMethodNotFoundException $e) {
44-
$this->assertEquals("The save method 'foo' was not found on the model of type: '$model'.", $e->getMessage());
45-
$this->assertEquals($model, $e->getModel());
46-
$this->assertEquals('foo', $e->getMethod());
44+
$this->assertSame("The save method 'foo' was not found on the model of type: '$model'.", $e->getMessage());
45+
$this->assertSame($model, $e->getModel());
46+
$this->assertSame('foo', $e->getMethod());
4747
$this->assertInstanceOf($model, $e->getObject());
4848
$this->reload();
4949
throw $e;
@@ -64,10 +64,10 @@ public function testShouldThrowExceptionAfterDeleteMethodRename()
6464
FactoryMuffin::deleteSaved();
6565
} catch (DeletingFailedException $e) {
6666
$exceptions = $e->getExceptions();
67-
$this->assertEquals("We encountered 1 problem(s) while trying to delete the saved models.", $e->getMessage());
68-
$this->assertEquals("The delete method 'bar' was not found on the model of type: '$model'.", $exceptions[0]->getMessage());
69-
$this->assertEquals($model, $exceptions[0]->getModel());
70-
$this->assertEquals('bar', $exceptions[0]->getMethod());
67+
$this->assertSame("We encountered 1 problem(s) while trying to delete the saved models.", $e->getMessage());
68+
$this->assertSame("The delete method 'bar' was not found on the model of type: '$model'.", $exceptions[0]->getMessage());
69+
$this->assertSame($model, $exceptions[0]->getModel());
70+
$this->assertSame('bar', $exceptions[0]->getMethod());
7171
$this->assertInstanceOf($model, $exceptions[0]->getObject());
7272
$this->reload();
7373
throw $e;
@@ -84,8 +84,8 @@ public function testShouldThrowExceptionOnModelSaveFailure()
8484
try {
8585
FactoryMuffin::create($model = 'ModelThatFailsToSaveStub');
8686
} catch (SaveFailedException $e) {
87-
$this->assertEquals("We could not save the model of type: '$model'.", $e->getMessage());
88-
$this->assertEquals($model, $e->getModel());
87+
$this->assertSame("We could not save the model of type: '$model'.", $e->getMessage());
88+
$this->assertSame($model, $e->getModel());
8989
$this->assertNull($e->getErrors());
9090
throw $e;
9191
}
@@ -101,8 +101,8 @@ public function testShouldThrowExceptionOnModelDeleteFailure()
101101
FactoryMuffin::deleteSaved();
102102
} catch (DeletingFailedException $e) {
103103
$exceptions = $e->getExceptions();
104-
$this->assertEquals("We encountered 1 problem(s) while trying to delete the saved models.", $e->getMessage());
105-
$this->assertEquals("We could not delete the model of type: '$model'.", $exceptions[0]->getMessage());
104+
$this->assertSame("We encountered 1 problem(s) while trying to delete the saved models.", $e->getMessage());
105+
$this->assertSame("We could not delete the model of type: '$model'.", $exceptions[0]->getMessage());
106106
throw $e;
107107
}
108108
}
@@ -117,8 +117,8 @@ public function testShouldAlsoThrowExceptionOnModelDeleteFailure()
117117
FactoryMuffin::deleteSaved();
118118
} catch (DeletingFailedException $e) {
119119
$exceptions = $e->getExceptions();
120-
$this->assertEquals("We encountered 1 problem(s) while trying to delete the saved models.", $e->getMessage());
121-
$this->assertEquals("OH NOES!", $exceptions[0]->getMessage());
120+
$this->assertSame("We encountered 1 problem(s) while trying to delete the saved models.", $e->getMessage());
121+
$this->assertSame("OH NOES!", $exceptions[0]->getMessage());
122122
throw $e;
123123
}
124124
}
@@ -131,9 +131,9 @@ public function testShouldThrowExceptionWithoutSaveMethod()
131131
try {
132132
FactoryMuffin::create($model = 'ModelWithNoSaveMethodStub');
133133
} catch (SaveMethodNotFoundException $e) {
134-
$this->assertEquals("The save method 'save' was not found on the model of type: '$model'.", $e->getMessage());
135-
$this->assertEquals($model, $e->getModel());
136-
$this->assertEquals('save', $e->getMethod());
134+
$this->assertSame("The save method 'save' was not found on the model of type: '$model'.", $e->getMessage());
135+
$this->assertSame($model, $e->getModel());
136+
$this->assertSame('save', $e->getMethod());
137137
$this->assertInstanceOf($model, $e->getObject());
138138
throw $e;
139139
}
@@ -149,10 +149,10 @@ public function testShouldThrowExceptionWithoutDeleteMethod()
149149
FactoryMuffin::deleteSaved();
150150
} catch (DeletingFailedException $e) {
151151
$exceptions = $e->getExceptions();
152-
$this->assertEquals("We encountered 1 problem(s) while trying to delete the saved models.", $e->getMessage());
153-
$this->assertEquals("The delete method 'delete' was not found on the model of type: '$model'.", $exceptions[0]->getMessage());
154-
$this->assertEquals($model, $exceptions[0]->getModel());
155-
$this->assertEquals('delete', $exceptions[0]->getMethod());
152+
$this->assertSame("We encountered 1 problem(s) while trying to delete the saved models.", $e->getMessage());
153+
$this->assertSame("The delete method 'delete' was not found on the model of type: '$model'.", $exceptions[0]->getMessage());
154+
$this->assertSame($model, $exceptions[0]->getModel());
155+
$this->assertSame('delete', $exceptions[0]->getMethod());
156156
$this->assertInstanceOf($model, $exceptions[0]->getObject());
157157
throw $e;
158158
}
@@ -166,9 +166,9 @@ public function testShouldThrowExceptionWithValidationErrors()
166166
try {
167167
FactoryMuffin::create($model = 'ModelWithValidationErrorsStub');
168168
} catch (SaveFailedException $e) {
169-
$this->assertEquals("Failed to save. We could not save the model of type: '$model'.", $e->getMessage());
170-
$this->assertEquals($model, $e->getModel());
171-
$this->assertEquals('Failed to save.', $e->getErrors());
169+
$this->assertSame("Failed to save. We could not save the model of type: '$model'.", $e->getMessage());
170+
$this->assertSame($model, $e->getModel());
171+
$this->assertSame('Failed to save.', $e->getErrors());
172172
throw $e;
173173
}
174174
}
@@ -184,11 +184,11 @@ public function testShouldThrowMultipleDeletionExceptions()
184184
FactoryMuffin::deleteSaved();
185185
} catch (DeletingFailedException $e) {
186186
$exceptions = $e->getExceptions();
187-
$this->assertEquals("We encountered 2 problem(s) while trying to delete the saved models.", $e->getMessage());
188-
$this->assertEquals("OH NOES!", $exceptions[0]->getMessage());
189-
$this->assertEquals("The delete method 'delete' was not found on the model of type: '$model'.", $exceptions[1]->getMessage());
190-
$this->assertEquals($model, $exceptions[1]->getModel());
191-
$this->assertEquals('delete', $exceptions[1]->getMethod());
187+
$this->assertSame("We encountered 2 problem(s) while trying to delete the saved models.", $e->getMessage());
188+
$this->assertSame("OH NOES!", $exceptions[0]->getMessage());
189+
$this->assertSame("The delete method 'delete' was not found on the model of type: '$model'.", $exceptions[1]->getMessage());
190+
$this->assertSame($model, $exceptions[1]->getModel());
191+
$this->assertSame('delete', $exceptions[1]->getMethod());
192192
$this->assertInstanceOf($model, $exceptions[1]->getObject());
193193
$this->assertInternalType('array', $e->getExceptions());
194194
$this->assertCount(2, $e->getExceptions());

0 commit comments

Comments
 (0)