Browse Source

Refactoring Tests (#6849)

Gabriel Caruso 7 years ago
parent
commit
a4b220273e

+ 1 - 1
tests/Composer/Test/AllFunctionalTest.php

@@ -93,7 +93,7 @@ class AllFunctionalTest extends TestCase
             $this->fail($proc->getOutput());
         }
 
-        $this->assertTrue(file_exists(self::$pharPath));
+        $this->assertFileExists(self::$pharPath);
     }
 
     /**

+ 7 - 7
tests/Composer/Test/Autoload/AutoloadGeneratorTest.php

@@ -378,7 +378,7 @@ class AutoloadGeneratorTest extends TestCase
 
         $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, '_5');
         $this->assertAutoloadFiles('vendors', $this->vendorDir.'/composer');
-        $this->assertTrue(file_exists($this->vendorDir.'/composer/autoload_classmap.php'), "ClassMap file needs to be generated, even if empty.");
+        $this->assertFileExists($this->vendorDir.'/composer/autoload_classmap.php', "ClassMap file needs to be generated, even if empty.");
     }
 
     public function testPSRToClassMapIgnoresNonExistingDir()
@@ -395,7 +395,7 @@ class AutoloadGeneratorTest extends TestCase
             ->will($this->returnValue(array()));
 
         $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', true, '_8');
-        $this->assertTrue(file_exists($this->vendorDir.'/composer/autoload_classmap.php'), "ClassMap file needs to be generated.");
+        $this->assertFileExists($this->vendorDir.'/composer/autoload_classmap.php', "ClassMap file needs to be generated.");
         $this->assertEquals(
             array(),
             include $this->vendorDir.'/composer/autoload_classmap.php'
@@ -425,7 +425,7 @@ class AutoloadGeneratorTest extends TestCase
         file_put_contents($this->vendorDir.'/b/b/lib/c.php', '<?php class ClassMapBaz {}');
 
         $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, '_6');
-        $this->assertTrue(file_exists($this->vendorDir.'/composer/autoload_classmap.php'), "ClassMap file needs to be generated.");
+        $this->assertFileExists($this->vendorDir.'/composer/autoload_classmap.php', "ClassMap file needs to be generated.");
         $this->assertEquals(
             array(
                 'ClassMapBar' => $this->vendorDir.'/b/b/src/b.php',
@@ -461,7 +461,7 @@ class AutoloadGeneratorTest extends TestCase
         file_put_contents($this->vendorDir.'/b/b/src/c.php', '<?php class ClassMapBaz {}');
 
         $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, '_6');
-        $this->assertTrue(file_exists($this->vendorDir.'/composer/autoload_classmap.php'), "ClassMap file needs to be generated.");
+        $this->assertFileExists($this->vendorDir.'/composer/autoload_classmap.php', "ClassMap file needs to be generated.");
         $this->assertEquals(
             array(
                 'ClassMapBar' => $this->vendorDir.'/a/a/target/lib/b.php',
@@ -497,7 +497,7 @@ class AutoloadGeneratorTest extends TestCase
         file_put_contents($this->vendorDir.'/c/c/foo/test.php', '<?php class ClassMapBaz {}');
 
         $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, '_7');
-        $this->assertTrue(file_exists($this->vendorDir.'/composer/autoload_classmap.php'), "ClassMap file needs to be generated.");
+        $this->assertFileExists($this->vendorDir.'/composer/autoload_classmap.php', "ClassMap file needs to be generated.");
         $this->assertEquals(
             array(
                 'ClassMapBar' => $this->vendorDir.'/b/b/test.php',
@@ -539,7 +539,7 @@ class AutoloadGeneratorTest extends TestCase
         $this->generator->setApcu(true);
         $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, '_7');
 
-        $this->assertTrue(file_exists($this->vendorDir.'/composer/autoload_classmap.php'), "ClassMap file needs to be generated.");
+        $this->assertFileExists($this->vendorDir.'/composer/autoload_classmap.php', "ClassMap file needs to be generated.");
         $this->assertEquals(
             array(
                 'ClassMapBar' => $this->vendorDir.'/b/b/ClassMapBar.php',
@@ -930,7 +930,7 @@ EOF;
 
         $this->generator->dump($this->config, $this->repository, $package, $this->im, "composer", false, '_12');
 
-        $this->assertFalse(file_exists($this->vendorDir."/composer/include_paths.php"));
+        $this->assertFileNotExists($this->vendorDir."/composer/include_paths.php");
     }
 
     public function testPreAndPostEventsAreDispatchedDuringAutoloadDump()

+ 4 - 4
tests/Composer/Test/DependencyResolver/SolverTest.php

@@ -76,7 +76,7 @@ class SolverTest extends TestCase
             $this->fail('Unsolvable conflict did not result in exception.');
         } catch (SolverProblemsException $e) {
             $problems = $e->getProblems();
-            $this->assertEquals(1, count($problems));
+            $this->assertCount(1, $problems);
             $this->assertEquals(2, $e->getCode());
             $this->assertEquals("\n    - The requested package b could not be found in any version, there may be a typo in the package name.", $problems[0]->getPrettyString());
         }
@@ -671,7 +671,7 @@ class SolverTest extends TestCase
             $this->fail('Unsolvable conflict did not result in exception.');
         } catch (SolverProblemsException $e) {
             $problems = $e->getProblems();
-            $this->assertEquals(1, count($problems));
+            $this->assertCount(1, $problems);
 
             $msg = "\n";
             $msg .= "  Problem 1\n";
@@ -700,7 +700,7 @@ class SolverTest extends TestCase
             $this->fail('Unsolvable conflict did not result in exception.');
         } catch (SolverProblemsException $e) {
             $problems = $e->getProblems();
-            $this->assertEquals(1, count($problems));
+            $this->assertCount(1, $problems);
             // TODO assert problem properties
 
             $msg = "\n";
@@ -747,7 +747,7 @@ class SolverTest extends TestCase
             $this->fail('Unsolvable conflict did not result in exception.');
         } catch (SolverProblemsException $e) {
             $problems = $e->getProblems();
-            $this->assertEquals(1, count($problems));
+            $this->assertCount(1, $problems);
 
             $msg = "\n";
             $msg .= "  Problem 1\n";

+ 1 - 4
tests/Composer/Test/Installer/SuggestedPackagesReporterTest.php

@@ -47,10 +47,7 @@ class SuggestedPackagesReporterTest extends \PHPUnit_Framework_TestCase
      */
     public function testGetPackagesEmptyByDefault()
     {
-        $this->assertSame(
-            array(),
-            $this->suggestedPackagesReporter->getPackages()
-        );
+        $this->assertEmpty($this->suggestedPackagesReporter->getPackages());
     }
 
     /**

+ 1 - 1
tests/Composer/Test/Package/Dumper/ArrayDumperTest.php

@@ -73,7 +73,7 @@ class ArrayDumperTest extends \PHPUnit_Framework_TestCase
 
         $config = $this->dumper->dump($this->package);
 
-        $this->assertSame(true, $config['abandoned']);
+        $this->assertTrue($config['abandoned']);
     }
 
     public function testDumpAbandonedReplacement()

+ 4 - 4
tests/Composer/Test/Repository/ArrayRepositoryTest.php

@@ -23,7 +23,7 @@ class ArrayRepositoryTest extends TestCase
         $repo = new ArrayRepository;
         $repo->addPackage($this->getPackage('foo', '1'));
 
-        $this->assertEquals(1, count($repo));
+        $this->assertCount(1, $repo);
     }
 
     public function testRemovePackage()
@@ -34,11 +34,11 @@ class ArrayRepositoryTest extends TestCase
         $repo->addPackage($this->getPackage('foo', '1'));
         $repo->addPackage($package);
 
-        $this->assertEquals(2, count($repo));
+        $this->assertCount(2, $repo);
 
         $repo->removePackage($this->getPackage('foo', '1'));
 
-        $this->assertEquals(1, count($repo));
+        $this->assertCount(1, $repo);
         $this->assertEquals(array($package), $repo->getPackages());
     }
 
@@ -77,7 +77,7 @@ class ArrayRepositoryTest extends TestCase
 
         $repo->addPackage($alias);
 
-        $this->assertEquals(2, count($repo));
+        $this->assertCount(2, $repo);
         $this->assertTrue($repo->hasPackage($this->getPackage('foo', '1')));
         $this->assertTrue($repo->hasPackage($this->getPackage('foo', '2')));
     }

+ 1 - 1
tests/Composer/Test/Repository/FilesystemRepositoryTest.php

@@ -36,7 +36,7 @@ class FilesystemRepositoryTest extends TestCase
 
         $packages = $repository->getPackages();
 
-        $this->assertSame(1, count($packages));
+        $this->assertCount(1, $packages);
         $this->assertSame('package1', $packages[0]->getName());
         $this->assertSame('1.0.0.0-beta', $packages[0]->getVersion());
         $this->assertSame('vendor', $packages[0]->getType());

+ 1 - 1
tests/Composer/Test/Repository/Pear/ChannelReaderTest.php

@@ -45,7 +45,7 @@ class ChannelReaderTest extends TestCase
         $this->assertEquals('MDB2', $packages[2]->getPackageName());
 
         $mdb2releases = $packages[2]->getReleases();
-        $this->assertEquals(9, count($mdb2releases['2.4.0']->getDependencyInfo()->getOptionals()));
+        $this->assertCount(9, $mdb2releases['2.4.0']->getDependencyInfo()->getOptionals());
     }
 
     public function testShouldSelectCorrectReader()

+ 4 - 4
tests/Composer/Test/Util/FilesystemTest.php

@@ -168,7 +168,7 @@ class FilesystemTest extends TestCase
 
         $fs = new Filesystem;
         $this->assertTrue($fs->removeDirectoryPhp($this->workingDir));
-        $this->assertFalse(file_exists($this->workingDir . "/level1/level2/hello.txt"));
+        $this->assertFileNotExists($this->workingDir . "/level1/level2/hello.txt");
     }
 
     public function testFileSize()
@@ -247,7 +247,7 @@ class FilesystemTest extends TestCase
         $fs = new Filesystem();
         $result = $fs->unlink($symlinked);
         $this->assertTrue($result);
-        $this->assertFalse(file_exists($symlinked));
+        $this->assertFileNotExists($symlinked);
     }
 
     /**
@@ -279,8 +279,8 @@ class FilesystemTest extends TestCase
 
         $result = $fs->removeDirectory($symlinkedTrailingSlash);
         $this->assertTrue($result);
-        $this->assertFalse(file_exists($symlinkedTrailingSlash));
-        $this->assertFalse(file_exists($symlinked));
+        $this->assertFileNotExists($symlinkedTrailingSlash);
+        $this->assertFileNotExists($symlinked);
     }
 
     public function testJunctions()