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

Initial support for Propel2 #45

merged 20 commits into from
Oct 29, 2017

Conversation

dantleech
Copy link
Contributor

Work-in-progress: Adds support for Propel2

public function flush()
{
$models = $this->persistedModels;
Propel::getConnection()->transaction(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inject connection

*/
private $generatedSqlPath;

public function __construct(string $generatedSqlPath)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately Propel doesn't allow runtime access to its configuration

));
}

$connection->exec(file_get_contents($sqlPath));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how well this will work regarding FK conflicts - the generated SQL is basically a dump with "DROP TABLE IF EXISTS ..." "CREATE TABLE ...".

It might otherwise be possible to build up a dependency graph for the models and purge them in order, but Propel doesn't make it easy.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also the tests are using Sqlite, which I don't think supports FKs - should probably make it use MySQL like the others.

@dantleech
Copy link
Contributor Author

Failing test is:

[PHP Fatal error:  Cannot declare class Fidry\AliceDataFixtures\Bridge\Doctrine\Entity\Dummy, because the name is already in use in /home/travis/build/theofidry/AliceDataFixtures/fixtures/Bridge/Doctrine/Entity/Dummy.php on line 21]

Not sure if that's a side effect of this PR.

sqlDir: tests/Bridge/Propel2/generated/sql
generator:
schema:
autoPackage: true
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This config is probably not required.

Copy link
Owner

@theofidry theofidry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Nice PR. Is there any integration tests?

{
"autoload-dev": {
"classmap": [
"../../tests/Bridge/Propel2/Model"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you shouldn't need that as this should be inherited thanks to theofidry/composer-inheritance-plugin

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But inherited from what? This namespace is manually mapped here because Propel doesn't allow PSR-4 IIRC.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok makes sense then

]
},
"require-dev": {
"propel/propel": "@alpha",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^2.0@alpha?

@dantleech
Copy link
Contributor Author

Nice PR. Is there any integration tests?

No! I missed those, will add.


$this->assertCount(5, AuthorQuery::create()->find());
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@theofidry this is the integration test as it stands - not sure if there is a better way to build the dependency tree above.

@theofidry
Copy link
Owner

@dantleech what's the status of this one? Is there still bits missing or is it just waiting for my review?

Copy link
Owner

@theofidry theofidry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok did a review, looks all good to me except some minor changes. Can you fix them ASAP? I would love to ship them in the next beta.

A mention in the README would also be nice, otherwise that's gonna be yet another undocumented feature :)

public function persist($object)
{
if (false === $object instanceof ActiveRecordInterface) {
throw new \InvalidArgumentException(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import this class with a use statement

public function create(PurgeMode $mode, PurgerInterface $purger = null): PurgerInterface
{
if ($mode == PurgeMode::createDeleteMode()) {
throw new \InvalidArgumentException(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this class should be imported with a use statement as well

$sqlPath = sprintf('%s/%s.sql', $this->generatedSqlPath, $this->connection->getName());

if (false === file_exists($sqlPath)) {
throw new \RuntimeException(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

*/
public function testCannotPersistANonModelObject()
{
$object = new \stdClass();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this class should be imported with a use statement

{
"autoload-dev": {
"classmap": [
"../../tests/Bridge/Propel2/Model"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok makes sense then

.gitignore Outdated
!/bin/test.sh
!/bin/cs.sh
/tests/Bridge/Propel2/generated
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can those two be moved in fixtures?

@theofidry theofidry changed the title [WIP] Initial support for Propel2 Initial support for Propel2 Oct 1, 2017
@dantleech
Copy link
Contributor Author

Tests are failing at the moment, so will need to find out why...

@dantleech
Copy link
Contributor Author

Updated, let's see what happens with the tests ...

@dantleech dantleech force-pushed the propel2 branch 2 times, most recently from 7236fce to 9007774 Compare October 1, 2017 18:49
@theofidry
Copy link
Owner

@dantleech I rebased your work and tweaks a few things, could you double check if everything is good for you?

@theofidry
Copy link
Owner

Merging as I really want to include this in the new release. Feel free to point out any error which can then be fixed for the next release.

Thanks again for that big contribution :)

@theofidry theofidry merged commit 7dfbb3a into theofidry:master Oct 29, 2017
@dantleech
Copy link
Contributor Author

Thanks @theofidry, sorry for not giving it more attention - hope it's a good foundation for Propel 2 support :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants