Skip to content

Commit

Permalink
Fix assertInternalType deprecation in phpunit 9
Browse files Browse the repository at this point in the history
  • Loading branch information
jderusse committed Aug 1, 2019
1 parent 4af1fd6 commit 9eba67d
Show file tree
Hide file tree
Showing 29 changed files with 147 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1466,7 +1466,7 @@ public function testSetDataEmptyArraySubmitNullMultiple()
]);
$form->setData($emptyArray);
$form->submit(null);
$this->assertInternalType('array', $form->getData());
$this->assertIsArray($form->getData());
$this->assertEquals([], $form->getData());
$this->assertEquals([], $form->getNormData());
$this->assertSame([], $form->getViewData(), 'View data is always an array');
Expand All @@ -1484,7 +1484,7 @@ public function testSetDataNonEmptyArraySubmitNullMultiple()
$existing = [0 => $entity1];
$form->setData($existing);
$form->submit(null);
$this->assertInternalType('array', $form->getData());
$this->assertIsArray($form->getData());
$this->assertEquals([], $form->getData());
$this->assertEquals([], $form->getNormData());
$this->assertSame([], $form->getViewData(), 'View data is always an array');
Expand Down
55 changes: 55 additions & 0 deletions src/Symfony/Bridge/PhpUnit/Legacy/ForwardCompatTestTraitForV5.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,59 @@ private function doTearDown()
{
parent::tearDown();
}

public static function assertIsArray($actual, string $message = ''): void
{
static::assertInternalType('array', $actual, $message);
}

public static function assertIsBool($actual, string $message = ''): void
{
static::assertInternalType('bool', $actual, $message);
}

public static function assertIsFloat($actual, string $message = ''): void
{
static::assertInternalType('float', $actual, $message);
}

public static function assertIsInt($actual, string $message = ''): void
{
static::assertInternalType('int', $actual, $message);
}

public static function assertIsNumeric($actual, string $message = ''): void
{
static::assertInternalType('numeric', $actual, $message);
}

public static function assertIsObject($actual, string $message = ''): void
{
static::assertInternalType('object', $actual, $message);
}

public static function assertIsResource($actual, string $message = ''): void
{
static::assertInternalType('resource', $actual, $message);
}

public static function assertIsString($actual, string $message = ''): void
{
static::assertInternalType('string', $actual, $message);
}

public static function assertIsScalar($actual, string $message = ''): void
{
static::assertInternalType('scalar', $actual, $message);
}

public static function assertIsCallable($actual, string $message = ''): void
{
static::assertInternalType('callable', $actual, $message);
}

public static function assertIsIterable($actual, string $message = ''): void
{
static::assertInternalType('iterable', $actual, $message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function testWarmUp()

$values = $fallbackPool->getValues();

$this->assertInternalType('array', $values);
$this->assertIsArray($values);
$this->assertCount(2, $values);
$this->assertArrayHasKey('Symfony_Bundle_FrameworkBundle_Tests_Fixtures_Serialization_Person', $values);
$this->assertArrayHasKey('Symfony_Bundle_FrameworkBundle_Tests_Fixtures_Serialization_Author', $values);
Expand All @@ -74,7 +74,7 @@ public function testWarmUpWithoutLoader()

$values = $fallbackPool->getValues();

$this->assertInternalType('array', $values);
$this->assertIsArray($values);
$this->assertCount(0, $values);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function testWarmUp()

$values = $fallbackPool->getValues();

$this->assertInternalType('array', $values);
$this->assertIsArray($values);
$this->assertCount(2, $values);
$this->assertArrayHasKey('Symfony.Bundle.FrameworkBundle.Tests.Fixtures.Validation.Person', $values);
$this->assertArrayHasKey('Symfony.Bundle.FrameworkBundle.Tests.Fixtures.Validation.Author', $values);
Expand Down Expand Up @@ -77,7 +77,7 @@ public function testWarmUpWithAnnotations()

$values = $fallbackPool->getValues();

$this->assertInternalType('array', $values);
$this->assertIsArray($values);
$this->assertCount(2, $values);
$this->assertArrayHasKey('Symfony.Bundle.FrameworkBundle.Tests.Fixtures.Validation.Category', $values);
$this->assertArrayHasKey('Symfony.Bundle.FrameworkBundle.Tests.Fixtures.Validation.SubCategory', $values);
Expand All @@ -99,7 +99,7 @@ public function testWarmUpWithoutLoader()

$values = $fallbackPool->getValues();

$this->assertInternalType('array', $values);
$this->assertIsArray($values);
$this->assertCount(0, $values);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function testProfilerIsDisabled($insulate)
$client->enableProfiler();
$this->assertFalse($client->getProfile());
$client->request('GET', '/profiler');
$this->assertInternalType('object', $client->getProfile());
$this->assertIsObject($client->getProfile());

$client->request('GET', '/profiler');
$this->assertFalse($client->getProfile());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@
namespace Symfony\Component\Config\Tests\Definition\Builder;

use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Tests\Fixtures\Builder\NodeBuilder as CustomNodeBuilder;

class TreeBuilderTest extends TestCase
{
use ForwardCompatTestTrait;

public function testUsingACustomNodeBuilder()
{
$builder = new TreeBuilder();
Expand Down Expand Up @@ -128,7 +131,7 @@ public function testDefinitionExampleGetsTransferredToNode()
$tree = $builder->buildTree();
$children = $tree->getChildren();

$this->assertInternalType('array', $tree->getExample());
$this->assertIsArray($tree->getExample());
$this->assertEquals('example', $children['child']->getExample());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerInterface as PsrContainerInterface;
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
use Symfony\Component\Config\Resource\ComposerResource;
use Symfony\Component\Config\Resource\DirectoryResource;
use Symfony\Component\Config\Resource\FileResource;
Expand Down Expand Up @@ -45,6 +46,8 @@

class ContainerBuilderTest extends TestCase
{
use ForwardCompatTestTrait;

public function testDefaultRegisteredDefinitions()
{
$builder = new ContainerBuilder();
Expand Down Expand Up @@ -168,7 +171,7 @@ public function testGetCreatesServiceBasedOnDefinition()
$builder = new ContainerBuilder();
$builder->register('foo', 'stdClass');

$this->assertInternalType('object', $builder->get('foo'), '->get() returns the service definition associated with the id');
$this->assertIsObject($builder->get('foo'), '->get() returns the service definition associated with the id');
}

public function testGetReturnsRegisteredService()
Expand Down Expand Up @@ -662,7 +665,7 @@ public function testResolveEnvValuesWithArray()
$container->resolveEnvPlaceholders('%dummy%', true);
$container->resolveEnvPlaceholders('%dummy2%', true);

$this->assertInternalType('array', $container->resolveEnvPlaceholders('%dummy2%', true));
$this->assertIsArray($container->resolveEnvPlaceholders('%dummy2%', true));

foreach ($dummyArray as $key => $value) {
$this->assertArrayHasKey($key, $container->resolveEnvPlaceholders('%dummy2%', true));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ public function testAnonymousServices()

// Anonymous service in a callable
$factory = $definition->getFactory();
$this->assertInternalType('array', $factory);
$this->assertIsArray($factory);
$this->assertInstanceOf(Reference::class, $factory[0]);
$this->assertTrue($container->has((string) $factory[0]));
$this->assertRegExp('/^\d+_Quz~[._A-Za-z0-9]{7}$/', (string) $factory[0]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@
namespace Symfony\Component\DependencyInjection\Tests\ParameterBag;

use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
use Symfony\Component\DependencyInjection\ParameterBag\EnvPlaceholderParameterBag;

class EnvPlaceholderParameterBagTest extends TestCase
{
use ForwardCompatTestTrait;

/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
*/
Expand All @@ -42,7 +45,7 @@ public function testMergeWillNotDuplicateIdenticalParameters()
$placeholder = array_values($placeholderForVariable)[0];

$this->assertCount(1, $placeholderForVariable);
$this->assertInternalType('string', $placeholder);
$this->assertIsString($placeholder);
$this->assertContains($envVariableName, $placeholder);
}

Expand All @@ -65,7 +68,7 @@ public function testMergeWhereFirstBagIsEmptyWillWork()
$placeholder = array_values($placeholderForVariable)[0];

$this->assertCount(1, $placeholderForVariable);
$this->assertInternalType('string', $placeholder);
$this->assertIsString($placeholder);
$this->assertContains($envVariableName, $placeholder);
}

Expand Down
7 changes: 5 additions & 2 deletions src/Symfony/Component/DomCrawler/Tests/CrawlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@
namespace Symfony\Component\DomCrawler\Tests;

use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
use Symfony\Component\DomCrawler\Crawler;

class CrawlerTest extends TestCase
{
use ForwardCompatTestTrait;

public function testConstructor()
{
$crawler = new Crawler();
Expand Down Expand Up @@ -843,7 +846,7 @@ public function testChaining()
public function testLinks()
{
$crawler = $this->createTestCrawler('http://example.com/bar/')->selectLink('Foo');
$this->assertInternalType('array', $crawler->links(), '->links() returns an array');
$this->assertIsArray($crawler->links(), '->links() returns an array');

$this->assertCount(4, $crawler->links(), '->links() returns an array');
$links = $crawler->links();
Expand All @@ -855,7 +858,7 @@ public function testLinks()
public function testImages()
{
$crawler = $this->createTestCrawler('http://example.com/bar/')->selectImage('Bar');
$this->assertInternalType('array', $crawler->images(), '->images() returns an array');
$this->assertIsArray($crawler->images(), '->images() returns an array');

$this->assertCount(4, $crawler->images(), '->images() returns an array');
$images = $crawler->images();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@

namespace Symfony\Component\DomCrawler\Tests\Field;

use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
use Symfony\Component\DomCrawler\Field\FileFormField;

class FileFormFieldTest extends FormFieldTestCase
{
use ForwardCompatTestTrait;

public function testInitialize()
{
$node = $this->createNode('input', '', ['type' => 'file']);
Expand Down Expand Up @@ -55,7 +58,7 @@ public function testSetValue($method)

$this->assertEquals(basename(__FILE__), $value['name'], "->$method() sets the name of the file field");
$this->assertEquals('', $value['type'], "->$method() sets the type of the file field");
$this->assertInternalType('string', $value['tmp_name'], "->$method() sets the tmp_name of the file field");
$this->assertIsString($value['tmp_name'], "->$method() sets the tmp_name of the file field");
$this->assertFileExists($value['tmp_name'], "->$method() creates a copy of the file at the tmp_name path");
$this->assertEquals(0, $value['error'], "->$method() sets the error of the file field");
$this->assertEquals(filesize(__FILE__), $value['size'], "->$method() sets the size of the file field");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function testLoadTypeExtensions()
{
$typeExtensions = $this->extension->getTypeExtensions('Symfony\Component\Form\Extension\Core\Type\FormType');

$this->assertInternalType('array', $typeExtensions);
$this->assertIsArray($typeExtensions);
$this->assertCount(1, $typeExtensions);
$this->assertInstanceOf('Symfony\Component\Form\Extension\DataCollector\Type\DataCollectorTypeExtension', array_shift($typeExtensions));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\Component\Form\Tests\Extension\Validator\Type;

use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
use Symfony\Component\Form\Test\FormInterface;
use Symfony\Component\Form\Test\TypeTestCase;
use Symfony\Component\Validator\Constraints\GroupSequence;
Expand All @@ -20,6 +21,8 @@
*/
abstract class BaseValidatorExtensionTest extends TypeTestCase
{
use ForwardCompatTestTrait;

public function testValidationGroupNullByDefault()
{
$form = $this->createForm();
Expand Down Expand Up @@ -60,7 +63,7 @@ public function testValidationGroupsCanBeSetToCallback()
'validation_groups' => [$this, 'testValidationGroupsCanBeSetToCallback'],
]);

$this->assertInternalType('callable', $form->getConfig()->getOption('validation_groups'));
$this->assertIsCallable($form->getConfig()->getOption('validation_groups'));
}

public function testValidationGroupsCanBeSetToClosure()
Expand All @@ -69,7 +72,7 @@ public function testValidationGroupsCanBeSetToClosure()
'validation_groups' => function (FormInterface $form) { },
]);

$this->assertInternalType('callable', $form->getConfig()->getOption('validation_groups'));
$this->assertIsCallable($form->getConfig()->getOption('validation_groups'));
}

public function testValidationGroupsCanBeSetToGroupSequence()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function testConstructorWithSimpleTypes()

$response = new JsonResponse(0.1);
$this->assertEquals('0.1', $response->getContent());
$this->assertInternalType('string', $response->getContent());
$this->assertIsString($response->getContent());

$response = new JsonResponse(true);
$this->assertSame('true', $response->getContent());
Expand Down Expand Up @@ -145,7 +145,7 @@ public function testStaticCreateWithSimpleTypes()
$response = JsonResponse::create(0.1);
$this->assertInstanceOf('Symfony\Component\HttpFoundation\JsonResponse', $response);
$this->assertEquals('0.1', $response->getContent());
$this->assertInternalType('string', $response->getContent());
$this->assertIsString($response->getContent());

$response = JsonResponse::create(true);
$this->assertInstanceOf('Symfony\Component\HttpFoundation\JsonResponse', $response);
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/HttpFoundation/Tests/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1156,7 +1156,7 @@ public function testGetContentReturnsResource()
{
$req = new Request();
$retval = $req->getContent(true);
$this->assertInternalType('resource', $retval);
$this->assertIsResource($retval);
$this->assertEquals('', fread($retval, 1));
$this->assertTrue(feof($retval));
}
Expand All @@ -1166,7 +1166,7 @@ public function testGetContentReturnsResourceWhenContentSetInConstructor()
$req = new Request([], [], [], [], [], [], 'MyContent');
$resource = $req->getContent(true);

$this->assertInternalType('resource', $resource);
$this->assertIsResource($resource);
$this->assertEquals('MyContent', stream_get_contents($resource));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function testGetId()

$storage->start();
$id = $storage->getId();
$this->assertInternalType('string', $id);
$this->assertIsString($id);
$this->assertNotSame('', $id);

$storage->save();
Expand Down

0 comments on commit 9eba67d

Please sign in to comment.