123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242 |
- <?php
- /*
- * This file is part of PHP CS Fixer.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- * Dariusz Rumiński <dariusz.ruminski@gmail.com>
- *
- * This source file is subject to the MIT license that is bundled
- * with this source code in the file LICENSE.
- */
- namespace PhpCsFixer\Tests\Fixer\PhpUnit;
- use PhpCsFixer\Fixer\PhpUnit\PhpUnitTargetVersion;
- use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
- /**
- * @author SpacePossum
- *
- * @internal
- *
- * @covers \PhpCsFixer\Fixer\PhpUnit\PhpUnitDedicateAssertFixer
- */
- final class PhpUnitDedicateAssertFixerTest extends AbstractFixerTestCase
- {
- /**
- * @param string $expected
- * @param null|string $input
- * @param array $config
- *
- * @dataProvider provideTestFixCases
- */
- public function testFix($expected, $input = null, array $config = [])
- {
- $this->fixer->configure($config);
- $this->doTest($expected, $input);
- }
- public function provideTestFixCases()
- {
- $cases = [
- [
- '<?php
- $this->assertNan($a);
- $this->assertNan($a);
- $this->assertTrue(test\is_nan($a));
- $this->assertTrue(test\a\is_nan($a));
- ',
- '<?php
- $this->assertTrue(is_nan($a));
- $this->assertTrue(\is_nan($a));
- $this->assertTrue(test\is_nan($a));
- $this->assertTrue(test\a\is_nan($a));
- ',
- ],
- [
- '<?php
- $this->assertFileExists($a);
- $this->assertFileNotExists($a);
- $this->assertFileExists($a);
- $this->assertFileNotExists($a);
- ',
- '<?php
- $this->assertTrue(file_exists($a));
- $this->assertFalse(file_exists($a));
- $this->assertTrue(\file_exists($a));
- $this->assertFalse(\file_exists($a));
- ',
- ],
- [
- '<?php
- $this->assertNull($a);
- $this->assertNotNull($a);
- $this->assertNull($a);
- $this->assertNotNull($a, "my message");
- ',
- '<?php
- $this->assertTrue(is_null($a));
- $this->assertFalse(is_null($a));
- $this->assertTrue(\is_null($a));
- $this->assertFalse(\is_null($a), "my message");
- ',
- ],
- [
- '<?php
- $this->assertEmpty($a);
- $this->assertNotEmpty($a);
- ',
- '<?php
- $this->assertTrue(empty($a));
- $this->ASSERTFALSE(empty($a));
- ',
- ],
- [
- '<?php
- $this->assertInfinite($a);
- $this->assertFinite($a, "my message");
- $this->assertInfinite($a);
- $this->assertFinite($a, "my message");
- ',
- '<?php
- $this->assertTrue(is_infinite($a));
- $this->assertFalse(is_infinite($a), "my message");
- $this->assertTrue(\is_infinite($a));
- $this->assertFalse(\is_infinite($a), "my message");
- ',
- ],
- [
- '<?php
- $this->assertArrayHasKey("test", $a);
- $this->assertArrayNotHasKey($b, $a, $c);
- ',
- '<?php
- $this->assertTrue(\array_key_exists("test", $a));
- $this->ASSERTFALSE(array_key_exists($b, $a), $c);
- ',
- ],
- [
- '<?php
- $this->assertTrue(is_dir($a));
- $this->assertTrue(is_writable($a));
- $this->assertTrue(is_readable($a));
- ',
- null,
- ],
- [
- '<?php
- $this->assertTrue(is_dir($a));
- $this->assertTrue(is_writable($a));
- $this->assertTrue(is_readable($a));
- ',
- null,
- ['target' => PhpUnitTargetVersion::VERSION_3_0],
- ],
- [
- '<?php
- $this->assertDirectoryNotExists($a);
- $this->assertNotIsWritable($a);
- $this->assertNotIsReadable($a);
- ',
- '<?php
- $this->assertFalse(is_dir($a));
- $this->assertFalse(is_writable($a));
- $this->assertFalse(is_readable($a));
- ',
- ['target' => PhpUnitTargetVersion::VERSION_5_6],
- ],
- [
- '<?php
- $this->assertDirectoryExists($a);
- $this->assertIsWritable($a);
- $this->assertIsReadable($a);
- ',
- '<?php
- $this->assertTrue(is_dir($a));
- $this->assertTrue(is_writable($a));
- $this->assertTrue(is_readable($a));
- ',
- ['target' => PhpUnitTargetVersion::VERSION_NEWEST],
- ],
- ];
- foreach (['array', 'bool', 'callable', 'double', 'float', 'int', 'integer', 'long', 'numeric', 'object', 'resource', 'real', 'scalar', 'string'] as $type) {
- $cases[] = [
- sprintf('<?php $this->assertInternalType(\'%s\', $a);', $type),
- sprintf('<?php $this->assertTrue(is_%s($a));', $type),
- ];
- $cases[] = [
- sprintf('<?php $this->assertNotInternalType(\'%s\', $a);', $type),
- sprintf('<?php $this->assertFalse(is_%s($a));', $type),
- ];
- }
- $cases[] = [
- '<?php $this->assertInternalType(\'float\', $a, "my message");',
- '<?php $this->assertTrue(is_float( $a), "my message");',
- ];
- $cases[] = [
- '<?php $this->assertInternalType(\'float\', $a);',
- '<?php $this->assertTrue(\IS_FLOAT($a));',
- ];
- $cases[] = [
- '<?php $this->assertInternalType(#
- \'float\'#
- , #
- $a#
- #
- )#
- ;',
- '<?php $this->assertTrue(#
- \IS_FLOAT#
- (#
- $a#
- )#
- )#
- ;',
- ];
- return $cases;
- }
- public function provideTestFixLegacyCases()
- {
- return array_filter($this->provideTestFixCases(), function (array $case) { return !isset($case[2]); });
- }
- /**
- * @param string $expected
- *
- * @dataProvider provideNotFixCases
- */
- public function testNotFix($expected)
- {
- $this->doTest($expected);
- }
- public function provideNotFixCases()
- {
- return [
- [
- '<?php echo $this->assertTrue;',
- ],
- [
- '<?php echo $this->assertTrue?>',
- ],
- [
- '<?php
- const is_null = 1;
- $this->assertTrue(is_null);
- $this->assertTrue(is_int($a) && $b);
- $this->assertFalse(is_nan($a));
- $this->assertTrue(is_int($a) || \is_bool($b));
- $this->assertTrue($a&&is_int($a));
- ',
- ],
- ];
- }
- }
|