Skip to content

Commit

Permalink
minor #147 Don't always require mongodb for tests (ogizanagi)
Browse files Browse the repository at this point in the history
This PR was merged into the 1.x-dev branch.

Discussion
----------

Don't always require mongodb for tests

since it' a bit cumbersome for contributors not changing anything to the ODM integration to have to install the mongodb ext.

Commits
-------

c052146 Don't always require mongodb for tests
  • Loading branch information
ogizanagi committed Aug 4, 2021
2 parents e8e3c73 + c052146 commit c533ec1
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 40 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,15 @@ jobs:
if: ${{ matrix.allow-unstable }}

- name: 'Lock Symfony version'
run: composer require "symfony/symfony:${{ matrix.symfony-version }}" --no-update
run: composer require --no-update --ansi "symfony/symfony:${{ matrix.symfony-version }}"
if: ${{ matrix.symfony-version != '' }}

- name: 'Require Doctrine MongoDB dependencies'
run: composer require --no-update ${{ matrix.composer-flags }} --dev --no-interaction --ansi "doctrine/mongodb-odm:^2.2" "doctrine/mongodb-odm-bundle:^4.3"
if: ${{ matrix.php != '8.1' }} # For now: Could not install mongodb on PHP 8.1.0-dev

- name: 'Install dependencies'
run: composer update --prefer-dist ${{ matrix.composer-flags }}
run: composer update --prefer-dist ${{ matrix.composer-flags }} --ansi

- name: 'Run PHPUnit tests'
run: vendor/bin/simple-phpunit ${{ matrix.code-coverage && '--coverage-text --coverage-clover build/logs/clover.xml' }}
run: vendor/bin/simple-phpunit --testdox --verbose ${{ matrix.code-coverage && '--coverage-text --coverage-clover build/logs/clover.xml' }}
23 changes: 13 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@
###########

install:
composer remove --dev "symfony/symfony"
# Require "phpspec/prophecy" for PHPUnit 9 used when PHP 8+ is used
php -r "exit (PHP_MAJOR_VERSION == 8 ? 0 : 1);" \
&& composer config platform.php 7.4.99 \
&& composer require --dev --no-update "phpspec/prophecy-phpunit" || true
composer update
rm -f composer.lock
composer remove --no-interaction --dev "symfony/symfony" "doctrine/mongodb-odm" "doctrine/mongodb-odm-bundle"
composer update --prefer-dist

install-lowest:
composer require "symfony/symfony:4.4.x" --no-update --no-interaction --dev
Expand All @@ -18,23 +15,29 @@ install-highest:
composer require "symfony/symfony:5.4.x" --no-update --no-interaction --dev
composer update

install-odm:
rm -f composer.lock
composer require --no-interaction --dev "doctrine/mongodb-odm:^2.2" "doctrine/mongodb-odm-bundle:^4.3"
composer update --prefer-dist

########
# Test #
########

test:
vendor/bin/simple-phpunit

testdox:
vendor/bin/simple-phpunit --testdox --verbose

########
# Lint #
########

lint: lint-php-cs-fixer

fix-php-cs-fixer: export PHP_CS_FIXER_FUTURE_MODE = 1
fix-php-cs-fixer:
vendor/bin/php-cs-fixer fix --config=.php_cs --no-interaction
vendor/bin/php-cs-fixer fix --no-interaction

lint-php-cs-fixer: export PHP_CS_FIXER_FUTURE_MODE = 1
lint-php-cs-fixer:
vendor/bin/php-cs-fixer fix --config=.php_cs --no-interaction --dry-run --diff
vendor/bin/php-cs-fixer fix --no-interaction --dry-run --diff
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Table of Contents
* [Compare](#compare)
* [Shortcuts](#shortcuts)
* [Integrations](#integrations)
* [Doctrine DBAL](#doctrine)
* [Doctrine DBAL](#doctrine-dbal)
* [In a Symfony app](#in-a-symfony-app)
* [Create the DBAL type](#create-the-dbal-type)
* [Register the DBAL type](#register-the-dbal-type)
Expand Down Expand Up @@ -127,7 +127,7 @@ Providing our own package inspired from the best ones, on which we'll apply our
- Symfony Validator component integration with an enum constraint.
- Symfony VarDumper component integration with a dedicated caster.
- Symfony HttpKernel component integration with an enum resolver for controller arguments.
- Doctrine DBAL integration with abstract classes in order to persist your enumeration in database.
- Doctrine integration in order to persist your enumeration in database.
- Faker enum provider to generate random enum instances.
- An API Platform OpenApi/Swagger type for documentation generation.
- JavaScript enums code generation.
Expand Down Expand Up @@ -515,7 +515,7 @@ Otherwise, simply implement the static methods yourself.

# Integrations

## Doctrine
## Doctrine DBAL

You can store the raw value of an enumeration in the database, but still manipulate it as an object from your entities by [creating a custom DBAL type](http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/cookbook/custom-mapping-types.html), from scratch.

Expand Down Expand Up @@ -658,7 +658,7 @@ abstract class AbstractEnumType extends Type

Override those methods in order to satisfy your needs.

## Doctrine MongoDB ODM
## Doctrine ODM

You can store enumeration values as string or integer in your MongoDB database and manipulate them as objects thanks to [custom mapping types](https://www.doctrine-project.org/projects/doctrine-mongodb-odm/en/2.2/reference/custom-mapping-types.html) included in this library.

Expand All @@ -676,7 +676,6 @@ elao_enum:
It'll actually generate & register the types classes for you, saving you from writing this boilerplate code.
### Create the ODM type
First, create your ODM type by extending either `AbstractEnumType` (single value) or `AbstractCollectionEnumType` (multiple values):
Expand Down
2 changes: 0 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@
"doctrine/data-fixtures": "^1.2",
"doctrine/doctrine-bundle": "^1.12|^2.0",
"doctrine/orm": "^2.4",
"doctrine/mongodb-odm-bundle": "^4.2",
"doctrine/mongodb-odm": "^2.1",
"friendsofphp/php-cs-fixer": "^3.0",
"nelmio/alice": "^3.0",
"symfony/browser-kit": "^4.4|^5.1",
Expand Down
17 changes: 0 additions & 17 deletions tests/Fixtures/Integration/Symfony/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,6 @@ doctrine:
prefix: 'App\Entity'
alias: App

doctrine_mongodb:
connections:
default:
server: '%env(resolve:MONGODB_URL)%'
default_database: '%env(resolve:MONGODB_DB)%'
document_managers:
default:
mappings:
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Document'
prefix: 'App\Document'
alias: Document
types:
gender: 'Elao\Enum\Tests\Fixtures\Bridge\Doctrine\ODM\Types\GenderEnumType'

services:
logger:
class: Psr\Log\NullLogger
Expand Down
16 changes: 16 additions & 0 deletions tests/Fixtures/Integration/Symfony/config/mongodb.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
doctrine_mongodb:
connections:
default:
server: '%env(resolve:MONGODB_URL)%'
default_database: '%env(resolve:MONGODB_DB)%'
document_managers:
default:
mappings:
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Document'
prefix: 'App\Document'
alias: Document
types:
gender: 'Elao\Enum\Tests\Fixtures\Bridge\Doctrine\ODM\Types\GenderEnumType'
10 changes: 7 additions & 3 deletions tests/Fixtures/Integration/Symfony/src/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,23 @@ class Kernel extends BaseKernel
{
public function registerBundles()
{
return [
return array_filter([
new FrameworkBundle(),
new TwigBundle(),
new DoctrineBundle(),
new DoctrineMongoDBBundle(),
class_exists(DoctrineMongoDBBundle::class) ? new DoctrineMongoDBBundle() : null,
new ElaoEnumBundle(),
];
]);
}

public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load($this->getProjectDir() . '/config/config.yml');

if (class_exists(DoctrineMongoDBBundle::class)) {
$loader->load($this->getProjectDir() . '/config/mongodb.yml');
}

if (self::VERSION_ID < 50300) {
$loader->load($this->getProjectDir() . '/config/config_prev_5.3.0.yml');
} else {
Expand Down
8 changes: 8 additions & 0 deletions tests/Integration/Bridge/Doctrine/ODM/Type/EnumTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace Elao\Enum\Tests\Integration\Bridge\Doctrine\ODM\Type;

use App\Document\User;
use Doctrine\Bundle\MongoDBBundle\DoctrineMongoDBBundle;
use Doctrine\Common\DataFixtures\Purger\MongoDBPurger;
use Doctrine\ODM\MongoDB\DocumentManager;
use Elao\Enum\Tests\Fixtures\Enum\Gender;
Expand All @@ -22,6 +23,13 @@ class EnumTypeTest extends KernelTestCase
/** @var DocumentManager */
private $dm;

public static function setUpBeforeClass(): void
{
if (!class_exists(DoctrineMongoDBBundle::class)) {
self::markTestSkipped('Doctrine MongoDB ODM bundle not installed');
}
}

protected function setUp(): void
{
$kernel = static::bootKernel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ class CollectionEnumTypeTest extends TestCase

public static function setUpBeforeClass(): void
{
if (!class_exists(Type::class)) {
self::markTestSkipped('Doctrine MongoDB ODM not installed');
}

Type::addType(self::NAME, SimpleCollectionEnumType::class);
}

Expand Down
4 changes: 4 additions & 0 deletions tests/Unit/Bridge/Doctrine/ODM/Types/EnumTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ class EnumTypeTest extends TestCase

public static function setUpBeforeClass(): void
{
if (!class_exists(Type::class)) {
self::markTestSkipped('Doctrine MongoDB ODM not installed');
}

if (!Type::hasType(self::NAME)) {
Type::addType(self::NAME, GenderEnumType::class);
}
Expand Down
4 changes: 4 additions & 0 deletions tests/Unit/Bridge/Doctrine/ODM/Types/IntegerEnumTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ class IntegerEnumTypeTest extends TestCase

public static function setUpBeforeClass(): void
{
if (!class_exists(Type::class)) {
self::markTestSkipped('Doctrine MongoDB ODM not installed');
}

Type::addType(self::NAME, SimpleEnumType::class);
}

Expand Down
5 changes: 5 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
* @author Elao <contact@elao.com>
*/

use Symfony\Component\Filesystem\Filesystem;

date_default_timezone_set('UTC');

$loader = require __DIR__ . '/../vendor/autoload.php';
Expand All @@ -21,4 +23,7 @@
const PACKAGE_ROOT_DIR = __DIR__ . '/..';
const FIXTURES_DIR = __DIR__ . '/Fixtures';

// Empty generated symfony cache
(new Filesystem())->remove(__DIR__ . '/Fixtures/Integration/Symfony/var/cache');

return $loader;

0 comments on commit c533ec1

Please sign in to comment.