From 58b34d13e8976e4fce7a876df5a6be7b138813a3 Mon Sep 17 00:00:00 2001 From: Ion Bazan Date: Fri, 7 Feb 2020 14:35:07 +0800 Subject: [PATCH] fix risky tests (without any assertion) --- tests/Composer/Test/ConfigTest.php | 1 + .../Test/Downloader/FossilDownloaderTest.php | 2 +- .../Test/Downloader/GitDownloaderTest.php | 2 +- .../Test/Downloader/HgDownloaderTest.php | 2 +- .../Test/Downloader/PerforceDownloaderTest.php | 3 +++ tests/Composer/Test/Package/BasePackageTest.php | 3 +++ .../Test/Package/Loader/ArrayLoaderTest.php | 8 ++++---- .../Test/Repository/Pear/ChannelReaderTest.php | 6 ++++-- .../Test/Repository/RepositoryManagerTest.php | 2 +- tests/Composer/Test/Util/ErrorHandlerTest.php | 17 +++++++++++------ tests/Composer/Test/Util/GitTest.php | 3 +++ 11 files changed, 33 insertions(+), 16 deletions(-) diff --git a/tests/Composer/Test/ConfigTest.php b/tests/Composer/Test/ConfigTest.php index 57c368988..750dd627d 100644 --- a/tests/Composer/Test/ConfigTest.php +++ b/tests/Composer/Test/ConfigTest.php @@ -222,6 +222,7 @@ class ConfigTest extends TestCase /** * @dataProvider allowedUrlProvider + * @doesNotPerformAssertions * * @param string $url */ diff --git a/tests/Composer/Test/Downloader/FossilDownloaderTest.php b/tests/Composer/Test/Downloader/FossilDownloaderTest.php index 623f7dec2..97706435d 100644 --- a/tests/Composer/Test/Downloader/FossilDownloaderTest.php +++ b/tests/Composer/Test/Downloader/FossilDownloaderTest.php @@ -153,7 +153,7 @@ class FossilDownloaderTest extends TestCase ->method('execute') ->with($this->equalTo($expectedResetCommand)); $filesystem = $this->getMockBuilder('Composer\Util\Filesystem')->getMock(); - $filesystem->expects($this->any()) + $filesystem->expects($this->once()) ->method('removeDirectory') ->with($this->equalTo('composerPath')) ->will($this->returnValue(true)); diff --git a/tests/Composer/Test/Downloader/GitDownloaderTest.php b/tests/Composer/Test/Downloader/GitDownloaderTest.php index 3713a850f..393ecfc5f 100644 --- a/tests/Composer/Test/Downloader/GitDownloaderTest.php +++ b/tests/Composer/Test/Downloader/GitDownloaderTest.php @@ -712,7 +712,7 @@ composer https://github.com/old/url (push) ->with($this->equalTo($expectedGitResetCommand)) ->will($this->returnValue(0)); $filesystem = $this->getMockBuilder('Composer\Util\Filesystem')->getMock(); - $filesystem->expects($this->any()) + $filesystem->expects($this->once()) ->method('removeDirectory') ->with($this->equalTo('composerPath')) ->will($this->returnValue(true)); diff --git a/tests/Composer/Test/Downloader/HgDownloaderTest.php b/tests/Composer/Test/Downloader/HgDownloaderTest.php index c71d463cb..c074e18dd 100644 --- a/tests/Composer/Test/Downloader/HgDownloaderTest.php +++ b/tests/Composer/Test/Downloader/HgDownloaderTest.php @@ -142,7 +142,7 @@ class HgDownloaderTest extends TestCase ->method('execute') ->with($this->equalTo($expectedResetCommand)); $filesystem = $this->getMockBuilder('Composer\Util\Filesystem')->getMock(); - $filesystem->expects($this->any()) + $filesystem->expects($this->once()) ->method('removeDirectory') ->with($this->equalTo('composerPath')) ->will($this->returnValue(true)); diff --git a/tests/Composer/Test/Downloader/PerforceDownloaderTest.php b/tests/Composer/Test/Downloader/PerforceDownloaderTest.php index ebb1f0456..3b5f4165c 100644 --- a/tests/Composer/Test/Downloader/PerforceDownloaderTest.php +++ b/tests/Composer/Test/Downloader/PerforceDownloaderTest.php @@ -103,6 +103,9 @@ class PerforceDownloaderTest extends TestCase return $repository; } + /** + * @doesNotPerformAssertions + */ public function testInitPerforceInstantiatesANewPerforceObject() { $this->downloader->initPerforce($this->package, $this->testPath, 'SOURCE_REF'); diff --git a/tests/Composer/Test/Package/BasePackageTest.php b/tests/Composer/Test/Package/BasePackageTest.php index 91d5e0491..33d384d69 100644 --- a/tests/Composer/Test/Package/BasePackageTest.php +++ b/tests/Composer/Test/Package/BasePackageTest.php @@ -17,6 +17,9 @@ use Composer\Test\TestCase; class BasePackageTest extends TestCase { + /** + * @doesNotPerformAssertions + */ public function testSetSameRepository() { $package = $this->getMockForAbstractClass('Composer\Package\BasePackage', array('foo')); diff --git a/tests/Composer/Test/Package/Loader/ArrayLoaderTest.php b/tests/Composer/Test/Package/Loader/ArrayLoaderTest.php index 9dfebdb5e..5ccaa038a 100644 --- a/tests/Composer/Test/Package/Loader/ArrayLoaderTest.php +++ b/tests/Composer/Test/Package/Loader/ArrayLoaderTest.php @@ -83,7 +83,7 @@ class ArrayLoaderTest extends TestCase $this->assertEquals('1.2.3.4', $package->getVersion()); } - public function testParseDumpProvider() + public function parseDumpProvider() { $validConfig = array( 'name' => 'A/B', @@ -142,7 +142,7 @@ class ArrayLoaderTest extends TestCase * The default parser should default to loading the config as this * allows require-dev libraries to have transport options included. * - * @dataProvider testParseDumpProvider + * @dataProvider parseDumpProvider */ public function testParseDumpDefaultLoadConfig($config) { @@ -153,7 +153,7 @@ class ArrayLoaderTest extends TestCase } /** - * @dataProvider testParseDumpProvider + * @dataProvider parseDumpProvider */ public function testParseDumpTrueLoadConfig($config) { @@ -165,7 +165,7 @@ class ArrayLoaderTest extends TestCase } /** - * @dataProvider testParseDumpProvider + * @dataProvider parseDumpProvider */ public function testParseDumpFalseLoadConfig($config) { diff --git a/tests/Composer/Test/Repository/Pear/ChannelReaderTest.php b/tests/Composer/Test/Repository/Pear/ChannelReaderTest.php index e766065a7..74e3c0c25 100644 --- a/tests/Composer/Test/Repository/Pear/ChannelReaderTest.php +++ b/tests/Composer/Test/Repository/Pear/ChannelReaderTest.php @@ -62,8 +62,10 @@ class ChannelReaderTest extends TestCase $reader = new \Composer\Repository\Pear\ChannelReader($rfs); - $reader->read('http://pear.1.0.net/'); - $reader->read('http://pear.1.1.net/'); + $pear10 = $reader->read('http://pear.1.0.net/'); + $this->assertCount(2, $pear10->getPackages()); + $pear11 = $reader->read('http://pear.1.1.net/'); + $this->assertCount(3, $pear11->getPackages()); } public function testShouldCreatePackages() diff --git a/tests/Composer/Test/Repository/RepositoryManagerTest.php b/tests/Composer/Test/Repository/RepositoryManagerTest.php index 3774dd268..f09b55ad8 100644 --- a/tests/Composer/Test/Repository/RepositoryManagerTest.php +++ b/tests/Composer/Test/Repository/RepositoryManagerTest.php @@ -84,7 +84,7 @@ class RepositoryManagerTest extends TestCase $rm->setRepositoryClass('artifact', 'Composer\Repository\ArtifactRepository'); $rm->createRepository('composer', array('url' => 'http://example.org')); - $rm->createRepository($type, $options); + $this->assertInstanceOf('Composer\Repository\RepositoryInterface', $rm->createRepository($type, $options)); } public function creationCases() diff --git a/tests/Composer/Test/Util/ErrorHandlerTest.php b/tests/Composer/Test/Util/ErrorHandlerTest.php index 52de96af4..89cc8b4dc 100644 --- a/tests/Composer/Test/Util/ErrorHandlerTest.php +++ b/tests/Composer/Test/Util/ErrorHandlerTest.php @@ -20,6 +20,16 @@ use Composer\Test\TestCase; */ class ErrorHandlerTest extends TestCase { + public function setUp() + { + ErrorHandler::register(); + } + + public function tearDown() + { + restore_error_handler(); + } + /** * Test ErrorHandler handles notices */ @@ -27,8 +37,6 @@ class ErrorHandlerTest extends TestCase { $this->setExpectedException('\ErrorException', 'Undefined index: baz'); - ErrorHandler::register(); - $array = array('foo' => 'bar'); $array['baz']; } @@ -40,18 +48,15 @@ class ErrorHandlerTest extends TestCase { $this->setExpectedException('\ErrorException', 'array_merge'); - ErrorHandler::register(); - array_merge(array(), 'string'); } /** * Test ErrorHandler handles warnings + * @doesNotPerformAssertions */ public function testErrorHandlerRespectsAtOperator() { - ErrorHandler::register(); - @trigger_error('test', E_USER_NOTICE); } } diff --git a/tests/Composer/Test/Util/GitTest.php b/tests/Composer/Test/Util/GitTest.php index a4f2c3f24..d534573d6 100644 --- a/tests/Composer/Test/Util/GitTest.php +++ b/tests/Composer/Test/Util/GitTest.php @@ -102,6 +102,7 @@ class GitTest extends TestCase $this->mockConfig($protocol); $this->process + ->expects($this->atLeast(2)) ->method('execute') ->willReturnMap(array( array('git command failing', null, null, 1), @@ -113,11 +114,13 @@ class GitTest extends TestCase ->willReturn(false); $this->io + ->expects($this->atLeastOnce()) ->method('hasAuthentication') ->with($this->equalTo('github.com')) ->willReturn(true); $this->io + ->expects($this->atLeastOnce()) ->method('getAuthentication') ->with($this->equalTo('github.com')) ->willReturn(array('username' => 'token', 'password' => $gitHubToken));