Skip to content
This repository
Browse code

Merge pull request #77 from djlambert/update-tests

Update tests with more applicable assertions
  • Loading branch information...
commit cd03a6dee6f5ca1c680f2066b32c92320f3421d7 2 parents 379a5f1 + 0df1319
Jonathan H. Wage authored September 17, 2012
64  tests/Doctrine/Tests/Common/DataFixtures/DependentFixtureTest.php
@@ -25,8 +25,6 @@
25 25
 use Doctrine\Common\DataFixtures\FixtureInterface;
26 26
 use Doctrine\Common\Persistence\ObjectManager;
27 27
 
28  
-require_once __DIR__.'/TestInit.php';
29  
-
30 28
 /**
31 29
  * Test Fixture ordering by dependencies.
32 30
  *
@@ -44,12 +42,11 @@ public function test_orderFixturesByDependencies_orderClassesWithASingleParent()
44 42
 
45 43
         $orderedFixtures = $loader->getFixtures();
46 44
 
47  
-        $this->assertEquals(4, count($orderedFixtures));
48  
-
49  
-        $this->assertTrue(array_shift($orderedFixtures) instanceof BaseParentFixture1);
50  
-        $this->assertTrue(array_shift($orderedFixtures) instanceof DependentFixture1);
51  
-        $this->assertTrue(array_shift($orderedFixtures) instanceof DependentFixture2);
52  
-        $this->assertTrue(array_shift($orderedFixtures) instanceof DependentFixture3);
  45
+        $this->assertCount(4, $orderedFixtures);
  46
+        $this->assertInstanceOf(__NAMESPACE__ . '\BaseParentFixture1', array_shift($orderedFixtures));
  47
+        $this->assertInstanceOf(__NAMESPACE__ . '\DependentFixture1', array_shift($orderedFixtures));
  48
+        $this->assertInstanceOf(__NAMESPACE__ . '\DependentFixture2', array_shift($orderedFixtures));
  49
+        $this->assertInstanceOf(__NAMESPACE__ . '\DependentFixture3', array_shift($orderedFixtures));
53 50
     }
54 51
 
55 52
     public function test_orderFixturesByDependencies_orderClassesWithAMultipleParents()
@@ -72,7 +69,7 @@ public function test_orderFixturesByDependencies_orderClassesWithAMultipleParent
72 69
 
73 70
         $orderedFixtures = $loader->getFixtures();
74 71
 
75  
-        $this->assertEquals(6, count($orderedFixtures));
  72
+        $this->assertCount(6, $orderedFixtures);
76 73
 
77 74
         $contactFixtureOrder = array_search($contactFixture, $orderedFixtures);
78 75
         $contactMethodFixtureOrder = array_search($contactMethodFixture, $orderedFixtures);
@@ -80,10 +77,10 @@ public function test_orderFixturesByDependencies_orderClassesWithAMultipleParent
80 77
         $countryFixtureOrder = array_search($countryFixture, $orderedFixtures);
81 78
         $stateFixtureOrder = array_search($stateFixture, $orderedFixtures);
82 79
         $baseParentFixtureOrder = array_search($baseParentFixture, $orderedFixtures);
83  
-        
  80
+
84 81
         // Order of fixtures is not exact. We need to test, however, that dependencies are
85 82
         // indeed satisfied
86  
-        
  83
+
87 84
         // BaseParentFixture1 has no dependencies, so it will always be first in this case
88 85
         $this->assertEquals($baseParentFixtureOrder, 0);
89 86
 
@@ -104,7 +101,7 @@ public function test_orderFixturesByDependencies_orderClassesWithAMultipleParent
104 101
     public function test_orderFixturesByDependencies_circularReferencesMakeMethodThrowCircularReferenceException()
105 102
     {
106 103
         $loader = new Loader();
107  
-        
  104
+
108 105
         $loader->addFixture(new CircularReferenceFixture3);
109 106
         $loader->addFixture(new CircularReferenceFixture);
110 107
         $loader->addFixture(new CircularReferenceFixture2);
@@ -118,7 +115,7 @@ public function test_orderFixturesByDependencies_circularReferencesMakeMethodThr
118 115
     public function test_orderFixturesByDependencies_fixturesCantHaveItselfAsParent()
119 116
     {
120 117
         $loader = new Loader();
121  
-        
  118
+
122 119
         $loader->addFixture(new FixtureWithItselfAsParent);
123 120
 
124 121
         $orderedFixtures = $loader->getFixtures();
@@ -137,15 +134,14 @@ public function test_inCaseThereAreFixturesOrderedByNumberAndByDependenciesBothO
137 134
 
138 135
         $orderedFixtures = $loader->getFixtures();
139 136
 
140  
-        $this->assertEquals(7, count($orderedFixtures));
141  
-        
142  
-        $this->assertTrue(array_shift($orderedFixtures) instanceof OrderedByNumberFixture1);
143  
-        $this->assertTrue(array_shift($orderedFixtures) instanceof OrderedByNumberFixture2);
144  
-        $this->assertTrue(array_shift($orderedFixtures) instanceof OrderedByNumberFixture3);
145  
-        $this->assertTrue(array_shift($orderedFixtures) instanceof BaseParentFixture1);
146  
-        $this->assertTrue(array_shift($orderedFixtures) instanceof DependentFixture1);
147  
-        $this->assertTrue(array_shift($orderedFixtures) instanceof DependentFixture2);
148  
-        $this->assertTrue(array_shift($orderedFixtures) instanceof DependentFixture3);
  137
+        $this->assertCount(7, $orderedFixtures);
  138
+        $this->assertInstanceOf(__NAMESPACE__ . '\OrderedByNumberFixture1', array_shift($orderedFixtures));
  139
+        $this->assertInstanceOf(__NAMESPACE__ . '\OrderedByNumberFixture2', array_shift($orderedFixtures));
  140
+        $this->assertInstanceOf(__NAMESPACE__ . '\OrderedByNumberFixture3', array_shift($orderedFixtures));
  141
+        $this->assertInstanceOf(__NAMESPACE__ . '\BaseParentFixture1', array_shift($orderedFixtures));
  142
+        $this->assertInstanceOf(__NAMESPACE__ . '\DependentFixture1', array_shift($orderedFixtures));
  143
+        $this->assertInstanceOf(__NAMESPACE__ . '\DependentFixture2', array_shift($orderedFixtures));
  144
+        $this->assertInstanceOf(__NAMESPACE__ . '\DependentFixture3', array_shift($orderedFixtures));
149 145
     }
150 146
 
151 147
     /**
@@ -206,7 +202,7 @@ public function load(ObjectManager $manager)
206 202
 
207 203
     public function getDependencies()
208 204
     {
209  
-        return array( 
  205
+        return array(
210 206
             'Doctrine\Tests\Common\DataFixtures\BaseParentFixture1'
211 207
         );
212 208
     }
@@ -219,7 +215,7 @@ public function load(ObjectManager $manager)
219 215
 
220 216
     public function getDependencies()
221 217
     {
222  
-        return array( 
  218
+        return array(
223 219
             'Doctrine\Tests\Common\DataFixtures\BaseParentFixture1',
224 220
             'Doctrine\Tests\Common\DataFixtures\CountryFixture'
225 221
         );
@@ -233,7 +229,7 @@ public function load(ObjectManager $manager)
233 229
 
234 230
     public function getDependencies()
235 231
     {
236  
-        return array( 
  232
+        return array(
237 233
             'Doctrine\Tests\Common\DataFixtures\BaseParentFixture1',
238 234
             'Doctrine\Tests\Common\DataFixtures\CountryFixture',
239 235
             'Doctrine\Tests\Common\DataFixtures\StateFixture'
@@ -248,7 +244,7 @@ public function load(ObjectManager $manager)
248 244
 
249 245
     public function getDependencies()
250 246
     {
251  
-        return array( 
  247
+        return array(
252 248
             'Doctrine\Tests\Common\DataFixtures\BaseParentFixture1'
253 249
         );
254 250
     }
@@ -261,7 +257,7 @@ public function load(ObjectManager $manager)
261 257
 
262 258
     public function getDependencies()
263 259
     {
264  
-        return array( 
  260
+        return array(
265 261
             'Doctrine\Tests\Common\DataFixtures\AddressFixture',
266 262
             'Doctrine\Tests\Common\DataFixtures\ContactMethodFixture'
267 263
         );
@@ -275,7 +271,7 @@ public function load(ObjectManager $manager)
275 271
 
276 272
     public function getDependencies()
277 273
     {
278  
-        return array( 
  274
+        return array(
279 275
             'Doctrine\Tests\Common\DataFixtures\CircularReferenceFixture3'
280 276
         );
281 277
     }
@@ -288,7 +284,7 @@ public function load(ObjectManager $manager)
288 284
 
289 285
     public function getDependencies()
290 286
     {
291  
-        return array( 
  287
+        return array(
292 288
             'Doctrine\Tests\Common\DataFixtures\CircularReferenceFixture'
293 289
         );
294 290
     }
@@ -301,7 +297,7 @@ public function load(ObjectManager $manager)
301 297
 
302 298
     public function getDependencies()
303 299
     {
304  
-        return array( 
  300
+        return array(
305 301
             'Doctrine\Tests\Common\DataFixtures\CircularReferenceFixture2'
306 302
         );
307 303
     }
@@ -314,7 +310,7 @@ public function load(ObjectManager $manager)
314 310
 
315 311
     public function getDependencies()
316 312
     {
317  
-        return array( 
  313
+        return array(
318 314
             'Doctrine\Tests\Common\DataFixtures\FixtureWithItselfAsParent'
319 315
         );
320 316
     }
@@ -327,7 +323,7 @@ public function load(ObjectManager $manager)
327 323
 
328 324
     public function getDependencies()
329 325
     {
330  
-        return array( 
  326
+        return array(
331 327
             'UnexistentDependency'
332 328
         );
333 329
     }
@@ -337,7 +333,7 @@ class FixtureImplementingBothOrderingInterfaces implements FixtureInterface, Ord
337 333
 {
338 334
     public function load(ObjectManager $manager)
339 335
     {}
340  
-    
  336
+
341 337
     public function getOrder()
342 338
     {
343 339
         return 1;
@@ -345,7 +341,7 @@ public function getOrder()
345 341
 
346 342
     public function getDependencies()
347 343
     {
348  
-        return array( 
  344
+        return array(
349 345
             'Doctrine\Tests\Common\DataFixtures\FixtureWithItselfAsParent'
350 346
         );
351 347
     }
4  tests/Doctrine/Tests/Common/DataFixtures/LoaderTest.php
@@ -37,10 +37,10 @@ public function testLoader()
37 37
         $loader->addFixture($this->getMock('Doctrine\Common\DataFixtures\FixtureInterface', array(), array(), 'Mock2'));
38 38
         $loader->addFixture($this->getMock('Doctrine\Common\DataFixtures\SharedFixtureInterface', array(), array(), 'Mock3'));
39 39
 
40  
-        $this->assertEquals(3, count($loader->getFixtures()));
  40
+        $this->assertCount(3, $loader->getFixtures());
41 41
 
42 42
         $loader->loadFromDirectory(__DIR__.'/TestFixtures');
43  
-        $this->assertEquals(7, count($loader->getFixtures()));
  43
+        $this->assertCount(7, $loader->getFixtures());
44 44
         $this->assertTrue($loader->isTransient('TestFixtures\NotAFixture'));
45 45
         $this->assertFalse($loader->isTransient('TestFixtures\MyFixture1'));
46 46
     }
13  tests/Doctrine/Tests/Common/DataFixtures/OrderedFixtureTest.php
@@ -24,8 +24,6 @@
24 24
 use Doctrine\Common\DataFixtures\FixtureInterface;
25 25
 use Doctrine\Common\Persistence\ObjectManager;
26 26
 
27  
-require_once __DIR__.'/TestInit.php';
28  
-
29 27
 /**
30 28
  * Test Fixture ordering.
31 29
  *
@@ -42,11 +40,12 @@ public function testFixtureOrder()
42 40
         $loader->addFixture(new BaseFixture1);
43 41
 
44 42
         $orderedFixtures = $loader->getFixtures();
45  
-        $this->assertEquals(4, count($orderedFixtures));
46  
-        $this->assertTrue($orderedFixtures[0] instanceof BaseFixture1);
47  
-        $this->assertTrue($orderedFixtures[1] instanceof OrderedFixture2);
48  
-        $this->assertTrue($orderedFixtures[2] instanceof OrderedFixture1);
49  
-        $this->assertTrue($orderedFixtures[3] instanceof OrderedFixture3);
  43
+
  44
+        $this->assertCount(4, $orderedFixtures);
  45
+        $this->assertInstanceOf(__NAMESPACE__ . '\BaseFixture1', $orderedFixtures[0]);
  46
+        $this->assertInstanceOf(__NAMESPACE__ . '\OrderedFixture2', $orderedFixtures[1]);
  47
+        $this->assertInstanceOf(__NAMESPACE__ . '\OrderedFixture1', $orderedFixtures[2]);
  48
+        $this->assertInstanceOf(__NAMESPACE__ . '\OrderedFixture3', $orderedFixtures[3]);
50 49
     }
51 50
 }
52 51
 
17  tests/Doctrine/Tests/Common/DataFixtures/ProxyReferenceRepositoryTest.php
@@ -24,8 +24,6 @@
24 24
 use Doctrine\ORM\Tools\SchemaTool;
25 25
 use Doctrine\ORM\Proxy\Proxy;
26 26
 
27  
-require_once __DIR__.'/TestInit.php';
28  
-
29 27
 /**
30 28
  * Test ProxyReferenceRepository.
31 29
  *
@@ -48,7 +46,8 @@ public function testReferenceEntry()
48 46
         $referenceRepo->addReference('test', $role);
49 47
 
50 48
         $references = $referenceRepo->getReferences();
51  
-        $this->assertEquals(1, count($references));
  49
+
  50
+        $this->assertCount(1, $references);
52 51
         $this->assertArrayHasKey('test', $references);
53 52
         $this->assertInstanceOf(self::TEST_ENTITY_ROLE, $references['test']);
54 53
     }
@@ -103,7 +102,8 @@ public function testReferenceReconstruction()
103 102
         $roleFixture->load($em);
104 103
         // first test against managed state
105 104
         $ref = $referenceRepository->getReference('admin-role');
106  
-        $this->assertFalse($ref instanceof Proxy);
  105
+
  106
+        $this->assertNotInstanceOf('Doctrine\ORM\Proxy\Proxy', $ref);
107 107
 
108 108
         // test reference reconstruction from serialized data (was managed)
109 109
         $serializedData = $referenceRepository->serialize();
@@ -112,12 +112,14 @@ public function testReferenceReconstruction()
112 112
         $proxyReferenceRepository->unserialize($serializedData);
113 113
 
114 114
         $ref = $proxyReferenceRepository->getReference('admin-role');
115  
-        $this->assertTrue($ref instanceof Proxy);
  115
+
  116
+        $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $ref);
116 117
 
117 118
         // now test reference reconstruction from identity
118 119
         $em->clear();
119 120
         $ref = $referenceRepository->getReference('admin-role');
120  
-        $this->assertTrue($ref instanceof Proxy);
  121
+
  122
+        $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $ref);
121 123
 
122 124
         // test reference reconstruction from serialized data (was identity)
123 125
         $serializedData = $referenceRepository->serialize();
@@ -126,6 +128,7 @@ public function testReferenceReconstruction()
126 128
         $proxyReferenceRepository->unserialize($serializedData);
127 129
 
128 130
         $ref = $proxyReferenceRepository->getReference('admin-role');
129  
-        $this->assertTrue($ref instanceof Proxy);
  131
+
  132
+        $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $ref);
130 133
     }
131 134
 }
11  tests/Doctrine/Tests/Common/DataFixtures/ReferenceRepositoryTest.php
@@ -24,8 +24,6 @@
24 24
 use Doctrine\ORM\Tools\SchemaTool;
25 25
 use Doctrine\ORM\Proxy\Proxy;
26 26
 
27  
-require_once __DIR__.'/TestInit.php';
28  
-
29 27
 /**
30 28
  * Test ReferenceRepository.
31 29
  *
@@ -47,7 +45,8 @@ public function testReferenceEntry()
47 45
         $referenceRepo->addReference('test', $role);
48 46
 
49 47
         $references = $referenceRepo->getReferences();
50  
-        $this->assertEquals(1, count($references));
  48
+
  49
+        $this->assertCount(1, $references);
51 50
         $this->assertArrayHasKey('test', $references);
52 51
         $this->assertInstanceOf(self::TEST_ENTITY_ROLE, $references['test']);
53 52
     }
@@ -103,11 +102,13 @@ public function testReferenceReconstruction()
103 102
         $roleFixture->load($em);
104 103
         // first test against managed state
105 104
         $ref = $referenceRepository->getReference('admin-role');
106  
-        $this->assertFalse($ref instanceof Proxy);
  105
+
  106
+        $this->assertNotInstanceOf('Doctrine\ORM\Proxy\Proxy', $ref);
107 107
 
108 108
         // now test reference reconstruction from identity
109 109
         $em->clear();
110 110
         $ref = $referenceRepository->getReference('admin-role');
111  
-        $this->assertTrue($ref instanceof Proxy);
  111
+
  112
+        $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $ref);
112 113
     }
113 114
 }

0 notes on commit cd03a6d

Please sign in to comment.
Something went wrong with that request. Please try again.