Skip to content

Commit

Permalink
Fix/lifecyclecallbacks (#44)
Browse files Browse the repository at this point in the history
* Remove non-existing lifecycle callbacks

* Apply fixes from StyleCI

[ci skip] [skip ci]
  • Loading branch information
patrickbrouwers authored Jun 28, 2017
1 parent 5724dcd commit 2476612
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 52 deletions.
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ php:
- 5.5
- 5.6
- 7.0
- hhvm
- 7.1

before_script:
- travis_retry composer self-update
Expand All @@ -19,6 +19,4 @@ sudo: false
script: php vendor/bin/phpunit --coverage-clover=coverage.clover

matrix:
allow_failures:
- php: 7.0
fast_finish: true
31 changes: 11 additions & 20 deletions src/Builders/LifecycleEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Doctrine\ORM\Events;
use Doctrine\ORM\Mapping\Builder\ClassMetadataBuilder;
use InvalidArgumentException;
use LaravelDoctrine\Fluent\Buildable;

/**
Expand All @@ -14,12 +15,7 @@
* @method LifecycleEvents preUpdate(string $method)
* @method LifecycleEvents postUpdate(string $method)
* @method LifecycleEvents postLoad(string $method)
* @method LifecycleEvents loadClassMetadata(string $method)
* @method LifecycleEvents onClassMetadataNotFound(string $method)
* @method LifecycleEvents preFlush(string $method)
* @method LifecycleEvents onFlush(string $method)
* @method LifecycleEvents postFlush(string $method)
* @method LifecycleEvents onClear(string $method)
*/
class LifecycleEvents implements Buildable
{
Expand All @@ -32,19 +28,14 @@ class LifecycleEvents implements Buildable
* @var array
*/
private $events = [
Events::preRemove => [],
Events::postRemove => [],
Events::prePersist => [],
Events::postPersist => [],
Events::preUpdate => [],
Events::postUpdate => [],
Events::postLoad => [],
Events::loadClassMetadata => [],
Events::onClassMetadataNotFound => [],
Events::preFlush => [],
Events::onFlush => [],
Events::postFlush => [],
Events::onClear => [],
Events::preRemove => [],
Events::postRemove => [],
Events::prePersist => [],
Events::postPersist => [],
Events::preUpdate => [],
Events::postUpdate => [],
Events::postLoad => [],
Events::preFlush => [],
];

/**
Expand All @@ -63,7 +54,7 @@ public function __construct(ClassMetadataBuilder $builder)
* @param string $method
* @param array $args
*
* @throws \InvalidArgumentException
* @throws InvalidArgumentException
*
* @return LifecycleEvents
*/
Expand All @@ -75,7 +66,7 @@ public function __call($method, $args)
return call_user_func_array([$this, 'add'], $args);
}

throw new \InvalidArgumentException('Fluent builder method ['.$method.'] does not exist');
throw new InvalidArgumentException('Fluent builder method ['.$method.'] does not exist');
}

/**
Expand Down
8 changes: 4 additions & 4 deletions tests/Builders/BuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -657,20 +657,20 @@ public function test_events_can_be_associated_to_the_entity()
public function test_events_can_be_configured_through_a_callable()
{
$this->fluent->events(function (LifecycleEvents $events) {
$events->onClear('swipeFloor');
$events->onFlush('cleanToilet');
$events->preFlush('swipeFloor');
$events->postRemove('cleanToilet');
});

foreach ($this->fluent->getQueued() as $buildable) {
$buildable->build();
}

$this->assertTrue(
$this->fluent->getClassMetadata()->hasLifecycleCallbacks('onClear')
$this->fluent->getClassMetadata()->hasLifecycleCallbacks('preFlush')
);

$this->assertTrue(
$this->fluent->getClassMetadata()->hasLifecycleCallbacks('onFlush')
$this->fluent->getClassMetadata()->hasLifecycleCallbacks('postRemove')
);
}

Expand Down
25 changes: 0 additions & 25 deletions tests/Builders/LifecycleEventsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,36 +64,11 @@ public function test_post_load_event()
$this->doEventTest(Events::postLoad);
}

public function test_load_class_metadata_event()
{
$this->doEventTest(Events::loadClassMetadata);
}

public function test_on_class_metadata_not_found_event()
{
$this->doEventTest(Events::onClassMetadataNotFound);
}

public function test_pre_flush_event()
{
$this->doEventTest(Events::preFlush);
}

public function test_on_flush_event()
{
$this->doEventTest(Events::onFlush);
}

public function test_post_flush_event()
{
$this->doEventTest(Events::postFlush);
}

public function test_on_clear_event()
{
$this->doEventTest(Events::onClear);
}

public function test_fluent_builder_method_should_exist()
{
$this->setExpectedException(\InvalidArgumentException::class);
Expand Down

0 comments on commit 2476612

Please sign in to comment.