Skip to content
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

Initial support for Propel2 #45

Merged
merged 20 commits into from
Oct 29, 2017
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
10 changes: 6 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
/vendor/
/composer.lock
/coverage.xml
/fixtures/Bridge/Symfony/SymfonyApp/cache/*
/fixtures/Bridge/MongoDB/data/*
!/fixtures/Bridge/MongoDB/data/.gitkeep
/fixtures/Bridge/Propel2/generated
/fixtures/Bridge/Propel2/Model/
!/fixtures/Bridge/Propel2/Model/.gitkeep
/fixtures/Bridge/Symfony/SymfonyApp/cache/*
/phpunit.xml
/.php_cs.cache
/.phar/
/vendor-bin/*/bin/
/vendor-bin/*/vendor/
/vendor-bin/*/composer.lock
/vendor-bin/*/vendor/
/dist/
/bin/
!/bin/clear_cache.sh
!/bin/console
!/bin/doctrine_purge
!/bin/eloquent_migrate
!/bin/eloquent_rollback
!/bin/test.sh
!/bin/cs.sh
!/bin/propel_init
24 changes: 23 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,20 @@ refresh_mongodb_db:
refresh_phpcr: ## Refresh the MongoDB PHPCR database used
refresh_phpcr: vendor-bin/doctrine_phpcr/vendor/phpcrodm
mysql -u root -e "DROP DATABASE IF EXISTS fidry_alice_data_fixtures; CREATE DATABASE fidry_alice_data_fixtures;"

php vendor-bin/doctrine_phpcr/bin/phpcrodm jackalope:init:dbal --force
php vendor-bin/doctrine_phpcr/bin/phpcrodm doctrine:phpcr:register-system-node-types

remove_sf_cache: ## Removes cache generated by Symfony
remove_sf_cache:
rm -rf fixtures/Bridge/Symfony/cache/*

propel_init: ## Initialize Propel
propel_init: vendor-bin/propel2/bin/propel
bin/propel_init
composer bin propel2 dump-autoload


##
## Tests
##---------------------------------------------------------------------------
Expand Down Expand Up @@ -95,6 +102,12 @@ test_eloquent_bridge: vendor/bamarni \

vendor-bin/eloquent/bin/phpunit -c phpunit_eloquent.xml.dist


test_propel2_bridge: ## Run the tests for the Propel2 bridge
test_propel2_bridge: propel_init
vendor-bin/propel2/bin/phpunit -c phpunit_propel2.xml.dist


test_symfony_bridge: ## Run the tests for the Symfony bridge
test_symfony_bridge: vendor/bamarni \
vendor-bin/symfony/vendor/phpunit \
Expand Down Expand Up @@ -157,7 +170,9 @@ test_symfony_eloquent_bridge_proxy_manager: vendor/bamarni \
##---------------------------------------------------------------------------

cs: ## Run the CS Fixer
cs: remove_sf_cache vendor-bin/php-cs-fixer/vendor
cs: remove_sf_cache \
vendor/bamarni \
vendor-bin/php-cs-fixer/vendor
$(PHP_CS_FIXER) fix


Expand Down Expand Up @@ -240,3 +255,10 @@ vendor-bin/proxy-manager/composer.lock: vendor-bin/proxy-manager/composer.json
vendor-bin/proxy-manager/vendor/phpunit: vendor-bin/proxy-manager/composer.lock
composer bin proxy-manager update --ignore-platform-reqs $(COMPOSER_FLAGS) || true
composer bin proxy-manager update --ignore-platform-reqs $(COMPOSER_FLAGS)


vendor-bin/propel2/composer.lock: vendor-bin/propel2/composer.json
@echo vendor-bin/propel2/composer.lock is not up to date.

vendor-bin/propel2/bin/propel: vendor-bin/propel2/composer.lock
composer bin propel2 update $(COMPOSER_FLAGS)
14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,16 @@ AliceDataFixtures
You can use [Composer](https://getcomposer.org/) to install the library to your project:

```bash
composer require --dev theofidry/alice-data-fixtures:^1.0@beta nelmio/alice:^3.1
composer require --dev theofidry/alice-data-fixtures:^1.0@beta

# with Doctrine
composer require --dev theofidry/alice-data-fixtures:^1.0@beta \
nelmio/alice:^3.1 \
doctrine/orm:^2.5 \
doctrine/data-fixtures
composer require --dev theofidry/alice-data-fixtures:^1.0@beta doctrine/orm:^2.5 doctrine/data-fixtures

# with Eloquent
composer require --dev theofidry/alice-data-fixtures:^1.0@beta \
nelmio/alice:^3.1 \
illuminate/database:~5.3.0
composer require --dev theofidry/alice-data-fixtures:^1.0@beta illuminate/database:~5.3.0

# with Propel2
composer require --dev theofidry/alice-data-fixtures:^1.0@beta propel/propel:^2.0@alpha
```


Expand Down
Empty file.
12 changes: 12 additions & 0 deletions fixtures/Bridge/Propel2/files/example1.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#
# This file is part of the Fidry\AliceDataFixtures package.
#
# (c) Théo FIDRY <[email protected]>
#
# For the full copyright and license information, please view the LICENSE
# file that was distributed with this source code.
#
Fidry\AliceDataFixtures\Bridge\Propel2\Model\Author:
author{1..5}:
name: Foobar

19 changes: 19 additions & 0 deletions fixtures/Bridge/Propel2/schema/schema.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<database name="default" defaultIdMethod="native"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://xsd.propelorm.org/1.6/database.xsd"
namespace="Fidry\AliceDataFixtures\Bridge\Propel2\Model"
>
<table name="book" phpName="Book">
<column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true"/>
<column name="title" type="varchar" size="255" required="true"/>
<column name="author_id" type="integer" required="true"/>
<foreign-key foreignTable="author">
<reference local="author_id" foreign="id"/>
</foreign-key>
</table>

<table name="author" phpName="Author">
<column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true"/>
<column name="name" type="varchar" size="128" required="true"/>
</table>
</database>
34 changes: 34 additions & 0 deletions phpunit_propel2.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
~ This file is part of the Fidry\AliceDataFixtures package.
~
~ (c) Théo FIDRY <[email protected]>
~
~ For the full copyright and license information, please view the LICENSE
~ file that was distributed with this source code.
-->

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.0/phpunit.xsd"
bootstrap="tests/Bridge/Propel2/autoload.php"
colors="true"
forceCoversAnnotation="true"
beStrictAboutCoversAnnotation="true"
beStrictAboutTestsThatDoNotTestAnything="false"
stopOnFailure="true"
verbose="true">

<testsuites>
<testsuite name="Test Suite">
<directory>tests/Bridge/Propel2</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>src/Bridge/Propel2</directory>
</whitelist>
</filter>

</phpunit>
78 changes: 78 additions & 0 deletions src/Bridge/Propel2/Persister/ModelPersister.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

/*
* This file is part of the Fidry\AliceDataFixtures package.
*
* (c) Théo FIDRY <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Fidry\AliceDataFixtures\Bridge\Propel2\Persister;

use Fidry\AliceDataFixtures\Persistence\PersisterInterface;
use InvalidArgumentException;
use Nelmio\Alice\IsAServiceTrait;
use Propel\Runtime\ActiveRecord\ActiveRecordInterface;
use Propel\Runtime\Connection\ConnectionInterface;

/**
* @author Daniel Leech <[email protected]>
*
* @final
*/
/*final*/ class ModelPersister implements PersisterInterface
{
use IsAServiceTrait;

private $connection;

/**
* @var Model[]
*/
private $persistedModels = [];

public function __construct(ConnectionInterface $connection)
{
$this->connection = $connection;
}

/**
* @inheritdoc
*/
public function persist($object)
{
if (false === $object instanceof ActiveRecordInterface) {
throw new InvalidArgumentException(
sprintf(
'Expected object to be an instance of "%s", got "%s" instead.',
ActiveRecordInterface::class,
get_class($object)
)
);
}

$this->persistedModels[] = $object;
}

/**
* @inheritdoc
*/
public function flush()
{
$models = $this->persistedModels;

$this->connection->transaction(
function () use ($models) {
foreach ($models as $model) {
$model->save();
}
}
);

$this->persistedModels = [];
}
}
70 changes: 70 additions & 0 deletions src/Bridge/Propel2/Purger/ModelPurger.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

/*
* This file is part of the Fidry\AliceDataFixtures package.
*
* (c) Théo FIDRY <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Fidry\AliceDataFixtures\Bridge\Propel2\Purger;

use Fidry\AliceDataFixtures\Persistence\PurgeMode;
use Fidry\AliceDataFixtures\Persistence\PurgerFactoryInterface;
use Fidry\AliceDataFixtures\Persistence\PurgerInterface;
use Nelmio\Alice\IsAServiceTrait;
use Propel\Runtime\Connection\ConnectionInterface;
use Propel\Runtime\Propel;
use RuntimeException;

/**
* @author Daniel Leech <[email protected]>
*
* @final
*/
/*final*/ class ModelPurger implements PurgerInterface, PurgerFactoryInterface
{
use IsAServiceTrait;

private $connection;
private $generatedSqlPath;

public function __construct(ConnectionInterface $connection, string $generatedSqlPath)
{
$this->connection = $connection;
$this->generatedSqlPath = $generatedSqlPath;
}

/**
* @inheritdoc
*/
public function create(PurgeMode $mode, PurgerInterface $purger = null): PurgerInterface
{
// Do nothing

return new self($this->connection, $this->generatedSqlPath);
}

/**
* @inheritdoc
*/
public function purge()
{
$sqlPath = sprintf('%s/%s.sql', $this->generatedSqlPath, $this->connection->getName());

if (false === file_exists($sqlPath)) {
throw new RuntimeException(
sprintf(
'No propel generated SQL file exists at "%s", do you need to generate it?',
$sqlPath
)
);
}

$this->connection->exec(file_get_contents($sqlPath));
}
}
2 changes: 2 additions & 0 deletions src/Loader/ErrorTracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
declare(strict_types=1);

namespace Fidry\AliceDataFixtures\Loader;

use Throwable;

/**
* Utility class to keep track of the errors stacked while trying to load a given file.
*
* @private
*
* @deprecated
*/
final class ErrorTracker
Expand Down
2 changes: 2 additions & 0 deletions src/Loader/FileTracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
declare(strict_types=1);

namespace Fidry\AliceDataFixtures\Loader;

use InvalidArgumentException;

/**
* Utility class to keep track of the files being loaded.
*
* @private
*
* @deprecated
*/
final class FileTracker
Expand Down
1 change: 1 addition & 0 deletions src/Loader/MultiPassLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
* Alternative to {@se SimpleLoader} to load the files in a smarter way.
*
* @final
*
* @deprecated As of nelmio/alice 3.1.0 this class is unneeded. Will be removed in future versions.
*/
/*final*/ class MultiPassLoader implements LoaderInterface
Expand Down
2 changes: 1 addition & 1 deletion tests/Bridge/Eloquent/Persister/ModelPersisterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function testIsAPersister()
$this->assertTrue(is_a(ModelPersister::class, PersisterInterface::class, true));
}

public function testIsClonable()
public function testIsNotClonable()
{
$this->assertFalse((new ReflectionClass(ModelPersister::class))->isCloneable());
}
Expand Down
Empty file.
Loading