Skip to content

Commit

Permalink
Stop using array and object types in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
greg0ire committed Jul 7, 2022
1 parent 9e0c7de commit ed9d444
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 7 deletions.
6 changes: 6 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@
<file name="lib/Doctrine/ORM/Query/TreeWalkerChain.php"/>
</errorLevel>
</DeprecatedMethod>
<DeprecatedConstant>
<errorLevel type="suppress">
<!-- DBAL 3 backward compatibility -->
<file name="lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php"/>
</errorLevel>
</DeprecatedConstant>
<DocblockTypeContradiction>
<errorLevel type="suppress">
<!-- We're catching invalid input here. -->
Expand Down
6 changes: 6 additions & 0 deletions tests/Doctrine/Tests/ORM/Functional/SchemaValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
use Doctrine\Tests\DbalTypes\CustomIdObjectType;
use Doctrine\Tests\DbalTypes\NegativeToPositiveType;
use Doctrine\Tests\DbalTypes\UpperCaseStringType;
use Doctrine\Tests\Models\Generic\SerializationModel;
use Doctrine\Tests\OrmFunctionalTestCase;

use function array_keys;
use function class_exists;
use function constant;
use function implode;

Expand Down Expand Up @@ -68,6 +70,10 @@ public function testValidateModelSets(string $modelSet): void
$classes = [];

foreach (self::$modelSets[$modelSet] as $className) {
if ($modelSet === 'generic' && $className === SerializationModel::class && ! class_exists(Type\ArrayType::class)) {
continue;
}

$classes[] = $this->_em->getClassMetadata($className);
}

Expand Down
12 changes: 12 additions & 0 deletions tests/Doctrine/Tests/ORM/Functional/TypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

use DateTime;
use DateTimeZone;
use Doctrine\DBAL\Types\ArrayType;
use Doctrine\DBAL\Types\ObjectType;
use Doctrine\DBAL\Types\Types;
use Doctrine\Tests\Models\Generic\BooleanModel;
use Doctrine\Tests\Models\Generic\DateTimeModel;
Expand All @@ -14,6 +16,8 @@
use Doctrine\Tests\OrmFunctionalTestCase;
use stdClass;

use function class_exists;

class TypeTest extends OrmFunctionalTestCase
{
protected function setUp(): void
Expand Down Expand Up @@ -70,6 +74,10 @@ public function testBoolean(): void

public function testArray(): void
{
if (! class_exists(ArrayType::class)) {
self::markTestSkipped('Test valid for doctrine/dbal:3.x only.');
}

$serialize = new SerializationModel();
$serialize->array['foo'] = 'bar';
$serialize->array['bar'] = 'baz';
Expand All @@ -86,6 +94,10 @@ public function testArray(): void

public function testObject(): void
{
if (! class_exists(ObjectType::class)) {
self::markTestSkipped('Test valid for doctrine/dbal:3.x only.');
}

$serialize = new SerializationModel();
$serialize->object = new stdClass();

Expand Down
6 changes: 3 additions & 3 deletions tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use Doctrine\Tests\Models\DDC889\DDC889Class;
use Doctrine\Tests\Models\DDC889\DDC889Entity;
use Doctrine\Tests\Models\DDC889\DDC889SuperClass;
use Doctrine\Tests\Models\Generic\SerializationModel;
use Doctrine\Tests\Models\Generic\BooleanModel;
use Doctrine\Tests\Models\GH7141\GH7141Article;
use Doctrine\Tests\Models\GH7316\GH7316Article;
use Doctrine\Tests\Models\ValueObjects\Name;
Expand Down Expand Up @@ -154,8 +154,8 @@ public function testEmbeddedMapping(): void
public function testInvalidMappingFileException(): void
{
$this->expectException(\Doctrine\Persistence\Mapping\MappingException::class);
$this->expectExceptionMessage('Invalid mapping file \'Doctrine.Tests.Models.Generic.SerializationModel.dcm.xml\' for class \'Doctrine\Tests\Models\Generic\SerializationModel\'.');
$this->createClassMetadata(SerializationModel::class);
$this->expectExceptionMessage('Invalid mapping file \'Doctrine.Tests.Models.Generic.BooleanModel.dcm.xml\' for class \'Doctrine\Tests\Models\Generic\BooleanModel\'.');
$this->createClassMetadata(BooleanModel::class);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
<generator strategy="AUTO"/>
</id>

<field name="array" column="array" type="array"/>

<field name="object" column="object" type="object"/>
<field name="booleanField" column="boolean_field" type="boolean"/>
</entity>

</doctrine-mapping>
10 changes: 9 additions & 1 deletion tests/Doctrine/Tests/OrmFunctionalTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Types\ArrayType;
use Doctrine\DBAL\Types\Type;
use Doctrine\ORM\Cache\CacheConfiguration;
use Doctrine\ORM\Cache\DefaultCacheFactory;
Expand Down Expand Up @@ -180,6 +181,7 @@
use function array_reverse;
use function array_slice;
use function assert;
use function class_exists;
use function explode;
use function get_debug_type;
use function getenv;
Expand Down Expand Up @@ -560,7 +562,9 @@ protected function tearDown(): void
$conn->executeStatement('DELETE FROM boolean_model');
$conn->executeStatement('DELETE FROM date_time_model');
$conn->executeStatement('DELETE FROM decimal_model');
$conn->executeStatement('DELETE FROM serialize_model');
if (class_exists(ArrayType::class)) {
$conn->executeStatement('DELETE FROM serialize_model');
}
}

if (isset($this->_usedModelSets['routing'])) {
Expand Down Expand Up @@ -839,6 +843,10 @@ protected function setUp(): void
foreach ($this->_usedModelSets as $setName => $bool) {
if (! isset(static::$tablesCreated[$setName])) {
foreach (static::$modelSets[$setName] as $className) {
if ($setName === 'generic' && $className === SerializationModel::class && ! class_exists(ArrayType::class)) {
continue;
}

$classes[] = $this->_em->getClassMetadata($className);
}

Expand Down

0 comments on commit ed9d444

Please sign in to comment.