Skip to content

[Rector] add PHPUnitSetList::PHPUNIT_SPECIFIC_METHOD #5320

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
use Rector\Php71\Rector\FuncCall\CountOnNullRector;
use Rector\Php73\Rector\FuncCall\JsonThrowOnErrorRector;
use Rector\Php73\Rector\FuncCall\StringifyStrNeedlesRector;
use Rector\PHPUnit\Rector\MethodCall\AssertFalseStrposToContainsRector;
use Rector\PHPUnit\Rector\MethodCall\AssertIssetToSpecificMethodRector;
use Rector\PHPUnit\Set\PHPUnitSetList;
use Rector\Set\ValueObject\LevelSetList;
use Rector\Set\ValueObject\SetList;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
Expand All @@ -53,6 +56,7 @@
return static function (ContainerConfigurator $containerConfigurator): void {
$containerConfigurator->import(SetList::DEAD_CODE);
$containerConfigurator->import(LevelSetList::UP_TO_PHP_73);
$containerConfigurator->import(PHPUnitSetList::PHPUNIT_SPECIFIC_METHOD);

$parameters = $containerConfigurator->parameters();

Expand Down Expand Up @@ -109,6 +113,18 @@

// use mt_rand instead of random_int on purpose on non-cryptographically random
RandomFunctionRector::class,

// $this->assertTrue(isset($bar['foo']))
// and $this->assertArrayHasKey('foo', $bar)
// or $this->assertObjectHasAttribute('foo', $bar);
// are not the same
AssertIssetToSpecificMethodRector::class => [
__DIR__ . '/tests/system/Entity/EntityTest.php',
__DIR__ . '/tests/system/Session/SessionTest.php',
],

// assertContains() to string can't be used in PHPUnit 9.1
AssertFalseStrposToContainsRector::class,
]);

// auto import fully qualified class names
Expand Down
2 changes: 1 addition & 1 deletion tests/system/API/ResponseTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ public function testXMLFormatter()
$this->formatter = new XMLFormatter();
$controller = $this->makeController();

$this->assertSame('CodeIgniter\Format\XMLFormatter', get_class($this->formatter));
$this->assertInstanceOf('CodeIgniter\Format\XMLFormatter', $this->formatter);

$controller->respondCreated(['id' => 3], 'A Custom Reason');
$expected = <<<'EOH'
Expand Down
2 changes: 1 addition & 1 deletion tests/system/CLI/ConsoleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function testHeader()
$console = new Console($this->app);
$console->showHeader();
$result = CITestStreamFilter::$buffer;
$this->assertTrue(strpos($result, sprintf('CodeIgniter v%s Command Line Tool', CodeIgniter::CI_VERSION)) > 0);
$this->assertGreaterThan(0, strpos($result, sprintf('CodeIgniter v%s Command Line Tool', CodeIgniter::CI_VERSION)));
}

public function testNoHeader()
Expand Down
6 changes: 3 additions & 3 deletions tests/system/CommonSingleServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function testSingleServiceWithNoParamsSupplied(string $service): void
$service1 = single_service($service);
$service2 = single_service($service);

$this->assertSame(get_class($service1), get_class($service2));
$this->assertInstanceOf(get_class($service1), $service2);
$this->assertNotSame($service1, $service2);
}

Expand Down Expand Up @@ -62,7 +62,7 @@ public function testSingleServiceWithAtLeastOneParamSupplied(string $service): v
$service1 = single_service($service, ...$params);
$service2 = single_service($service, ...$params);

$this->assertSame(get_class($service1), get_class($service2));
$this->assertInstanceOf(get_class($service1), $service2);
$this->assertNotSame($service1, $service2);

if ($service === 'commands') {
Expand All @@ -77,7 +77,7 @@ public function testSingleServiceWithAllParamsSupplied(): void

// Assert that even passing true as last param this will
// not create a shared instance.
$this->assertSame(get_class($cache1), get_class($cache2));
$this->assertInstanceOf(get_class($cache1), $cache2);
$this->assertNotSame($cache1, $cache2);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/system/Config/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function testCreateSharedInstance()
$Config = Config::get('DocTypes');
$Config2 = Config::get('Config\\DocTypes');

$this->assertTrue($Config === $Config2);
$this->assertSame($Config2, $Config);
}

public function testCreateNonConfig()
Expand Down
2 changes: 1 addition & 1 deletion tests/system/Config/ServicesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ public function testReset()
$response2 = service('response');
$this->assertInstanceOf(MockResponse::class, $response2);

$this->assertTrue($response !== $response2);
$this->assertNotSame($response2, $response);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions tests/system/Cookie/CookieTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,13 +268,13 @@ public function testArrayAccessOfCookie(): void
{
$cookie = new Cookie('cookie', 'monster');

$this->assertTrue(isset($cookie['expire']));
$this->assertArrayHasKey('expire', $cookie);
$this->assertSame($cookie['expire'], $cookie->getExpiresTimestamp());
$this->assertTrue(isset($cookie['httponly']));
$this->assertArrayHasKey('httponly', $cookie);
$this->assertSame($cookie['httponly'], $cookie->isHTTPOnly());
$this->assertTrue(isset($cookie['samesite']));
$this->assertArrayHasKey('samesite', $cookie);
$this->assertSame($cookie['samesite'], $cookie->getSameSite());
$this->assertTrue(isset($cookie['path']));
$this->assertArrayHasKey('path', $cookie);
$this->assertSame($cookie['path'], $cookie->getPath());

$this->expectException(InvalidArgumentException::class);
Expand Down
2 changes: 1 addition & 1 deletion tests/system/Database/Live/ConnectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,6 @@ public function testConnectWithFailover()
$db1 = Database::connect($this->tests);

$this->assertSame($this->tests['failover'][0]['DBDriver'], $this->getPrivateProperty($db1, 'DBDriver'));
$this->assertTrue(count($db1->listTables()) >= 0);
$this->assertGreaterThanOrEqual(0, count($db1->listTables()));
}
}
2 changes: 1 addition & 1 deletion tests/system/Database/Live/DbUtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function testUtilsListDatabases()
if (in_array($this->db->DBDriver, ['MySQLi', 'Postgre', 'SQLSRV'], true)) {
$databases = $util->listDatabases();

$this->assertTrue(in_array($this->db->getDatabase(), $databases, true));
$this->assertContains($this->db->getDatabase(), $databases);
} elseif ($this->db->DBDriver === 'SQLite3') {
$this->expectException(DatabaseException::class);
$this->expectExceptionMessage('Unsupported feature of the database platform you are using.');
Expand Down
4 changes: 2 additions & 2 deletions tests/system/Database/Live/GetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ public function testGetFieldNames()
{
$jobs = $this->db->table('job')->get()->getFieldNames();

$this->assertTrue(in_array('name', $jobs, true));
$this->assertTrue(in_array('description', $jobs, true));
$this->assertContains('name', $jobs);
$this->assertContains('description', $jobs);
}

public function testGetFieldData()
Expand Down
2 changes: 1 addition & 1 deletion tests/system/Database/Live/PretendTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function testPretendReturnsQueryObject()
->table('user')
->get();

$this->assertFalse($result instanceof Query);
$this->assertNotInstanceOf(Query::class, $result);

$result = $this->db->pretend(true)
->table('user')
Expand Down
6 changes: 3 additions & 3 deletions tests/system/Database/Live/SQLite/AlterTableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ public function testDropColumnSuccess()

$columns = $this->db->getFieldNames('foo');

$this->assertFalse(in_array('name', $columns, true));
$this->assertTrue(in_array('id', $columns, true));
$this->assertTrue(in_array('email', $columns, true));
$this->assertNotContains('name', $columns);
$this->assertContains('id', $columns);
$this->assertContains('email', $columns);
}

public function testDropColumnMaintainsKeys()
Expand Down
14 changes: 7 additions & 7 deletions tests/system/Filters/FiltersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ public function testShortCircuit()
$uri = 'admin/foo/bar';
$response = $filters->run($uri, 'before');

$this->assertTrue($response instanceof ResponseInterface);
$this->assertInstanceOf(ResponseInterface::class, $response);
$this->assertSame('http://google.com', $response->csp);
}

Expand Down Expand Up @@ -737,7 +737,7 @@ public function testAddFilter()
$filters = $filters->initialize('admin/foo/bar');
$filters = $filters->getFilters();

$this->assertTrue(in_array('some_alias', $filters['before'], true));
$this->assertContains('some_alias', $filters['before']);
}

public function testAddFilterSection()
Expand All @@ -753,7 +753,7 @@ public function testAddFilterSection()
->initialize('admin/foo/bar')
->getFilters();

$this->assertTrue(in_array('another', $list['before'], true));
$this->assertContains('another', $list['before']);
}

public function testInitializeTwice()
Expand All @@ -770,7 +770,7 @@ public function testInitializeTwice()
->initialize()
->getFilters();

$this->assertTrue(in_array('another', $list['before'], true));
$this->assertContains('another', $list['before']);
}

public function testEnableFilter()
Expand All @@ -791,7 +791,7 @@ public function testEnableFilter()
$filters->enableFilter('google', 'before');
$filters = $filters->getFilters();

$this->assertTrue(in_array('google', $filters['before'], true));
$this->assertContains('google', $filters['before']);
}

public function testEnableFilterWithArguments()
Expand All @@ -813,7 +813,7 @@ public function testEnableFilterWithArguments()
$filters->enableFilter('role:admin , super', 'after');
$found = $filters->getFilters();

$this->assertTrue(in_array('role', $found['before'], true));
$this->assertContains('role', $found['before']);
$this->assertSame(['admin', 'super'], $filters->getArguments('role'));
$this->assertSame(['role' => ['admin', 'super']], $filters->getArguments());

Expand Down Expand Up @@ -845,7 +845,7 @@ public function testEnableFilterWithNoArguments()
$filters->enableFilter('role', 'after');
$found = $filters->getFilters();

$this->assertTrue(in_array('role', $found['before'], true));
$this->assertContains('role', $found['before']);

$response = $filters->run('admin/foo/bar', 'before');

Expand Down
4 changes: 2 additions & 2 deletions tests/system/HTTP/IncomingRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -544,8 +544,8 @@ public function testWithFalseBody()
// Use `false` here to simulate file_get_contents returning a false value
$request = new IncomingRequest(new App(), new URI(), false, new UserAgent());

$this->assertTrue($request->getBody() !== false);
$this->assertTrue($request->getBody() === null);
$this->assertNotFalse($request->getBody());
$this->assertNull($request->getBody());
}

/**
Expand Down
6 changes: 3 additions & 3 deletions tests/system/HTTP/ResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function testConstructWithCSPEnabled()
$config->CSPEnabled = true;
$response = new Response($config);

$this->assertTrue($response instanceof Response);
$this->assertInstanceOf(Response::class, $response);
}

public function testSetStatusCodeSetsReason()
Expand Down Expand Up @@ -327,7 +327,7 @@ public function testJSONWithArray()
$response->setJSON($body);

$this->assertSame($expected, $response->getJSON());
$this->assertTrue(strpos($response->getHeaderLine('content-type'), 'application/json') !== false);
$this->assertNotFalse(strpos($response->getHeaderLine('content-type'), 'application/json'));
}

public function testJSONGetFromNormalBody()
Expand Down Expand Up @@ -364,7 +364,7 @@ public function testXMLWithArray()
$response->setXML($body);

$this->assertSame($expected, $response->getXML());
$this->assertTrue(strpos($response->getHeaderLine('content-type'), 'application/xml') !== false);
$this->assertNotFalse(strpos($response->getHeaderLine('content-type'), 'application/xml'));
}

public function testXMLGetFromNormalBody()
Expand Down
2 changes: 1 addition & 1 deletion tests/system/I18n/TimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1023,7 +1023,7 @@ public function testCreateFromInstance()
{
$datetime = new DateTime();
$time = Time::createFromInstance($datetime);
$this->assertTrue($time instanceof Time);
$this->assertInstanceOf(Time::class, $time);
$this->assertTrue($time->sameAs($datetime));
}

Expand Down
10 changes: 5 additions & 5 deletions tests/system/Images/BaseHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ protected function setUp(): void
public function testNew()
{
$handler = Services::image('gd', null, false);
$this->assertTrue($handler instanceof BaseHandler);
$this->assertInstanceOf(BaseHandler::class, $handler);
}

public function testWithFile()
Expand All @@ -68,7 +68,7 @@ public function testWithFile()
$handler->withFile($path);

$image = $handler->getFile();
$this->assertTrue($image instanceof Image);
$this->assertInstanceOf(Image::class, $image);
$this->assertSame(155, $image->origWidth);
$this->assertSame($path, $image->getPathname());
}
Expand Down Expand Up @@ -104,15 +104,15 @@ public function testFileTypes()
$handler = Services::image('gd', null, false);
$handler->withFile($this->start . 'ci-logo.png');
$image = $handler->getFile();
$this->assertTrue($image instanceof Image);
$this->assertInstanceOf(Image::class, $image);

$handler->withFile($this->start . 'ci-logo.jpeg');
$image = $handler->getFile();
$this->assertTrue($image instanceof Image);
$this->assertInstanceOf(Image::class, $image);

$handler->withFile($this->start . 'ci-logo.gif');
$image = $handler->getFile();
$this->assertTrue($image instanceof Image);
$this->assertInstanceOf(Image::class, $image);
}

// Something handled by our Image
Expand Down
4 changes: 2 additions & 2 deletions tests/system/Images/ImageMagickHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ public function testGetVersion()
// make sure that the call worked
$this->assertNotFalse($version);
// we should have a numeric version, greater than 6
$this->assertTrue(version_compare($version, '6.0.0') >= 0);
$this->assertTrue(version_compare($version, '99.0.0') < 0);
$this->assertGreaterThanOrEqual(0, version_compare($version, '6.0.0'));
$this->assertLessThan(0, version_compare($version, '99.0.0'));
}

public function testImageProperties()
Expand Down
6 changes: 3 additions & 3 deletions tests/system/Language/LanguageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public function testLanguageFileLoading()
$this->lang = new SecondMockLanguage('en');

$this->lang->loadem('More', 'en');
$this->assertTrue(in_array('More', $this->lang->loaded(), true));
$this->assertContains('More', $this->lang->loaded());

$this->lang->loadem('More', 'en');
$this->assertCount(1, $this->lang->loaded()); // should only be there once
Expand All @@ -176,11 +176,11 @@ public function testLanguageFileLoadingReturns()
$this->lang = new SecondMockLanguage('en');

$result = $this->lang->loadem('More', 'en', true);
$this->assertFalse(in_array('More', $this->lang->loaded(), true));
$this->assertNotContains('More', $this->lang->loaded());
$this->assertCount(3, $result);

$result = $this->lang->loadem('More', 'en');
$this->assertTrue(in_array('More', $this->lang->loaded(), true));
$this->assertContains('More', $this->lang->loaded());
$this->assertCount(1, $this->lang->loaded());
}

Expand Down
4 changes: 2 additions & 2 deletions tests/system/Log/LoggerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public function testLogInterpolatesFileAndLine()

$logs = TestHandler::getLogs();

$this->assertTrue(strpos($logs[0], $expected) > 1);
$this->assertGreaterThan(1, strpos($logs[0], $expected));
}

public function testLogInterpolatesExceptions()
Expand All @@ -222,7 +222,7 @@ public function testLogInterpolatesExceptions()
$logs = TestHandler::getLogs();

$this->assertCount(1, $logs);
$this->assertTrue(strpos($logs[0], $expected) === 0);
$this->assertSame(0, strpos($logs[0], $expected));
}

public function testEmergencyLogsCorrectly()
Expand Down
2 changes: 1 addition & 1 deletion tests/system/Models/InsertModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function testInsertBatchValidationFail(): void
$this->assertFalse($this->model->insertBatch($jobData));

$error = $this->model->errors();
$this->assertTrue(isset($error['description']));
$this->assertArrayHasKey('description', $error);
}

public function testInsertBatchSetsIntTimestamps(): void
Expand Down
2 changes: 1 addition & 1 deletion tests/system/Models/MiscellaneousModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function testGetValidationMessagesForReplace(): void
$this->assertFalse($this->model->replace($jobData));

$error = $this->model->errors();
$this->assertTrue(isset($error['description']));
$this->assertArrayHasKey('description', $error);
}

public function testUndefinedTypeInTransformDataToArray(): void
Expand Down
2 changes: 1 addition & 1 deletion tests/system/Models/UpdateModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public function testUpdateBatchValidationFail(): void
$this->assertFalse($this->model->updateBatch($data, 'name'));

$error = $this->model->errors();
$this->assertTrue(isset($error['country']));
$this->assertArrayHasKey('country', $error);
}

public function testUpdateBatchWithEntity(): void
Expand Down
Loading