From 2476612db3d39a570b837f9ed2c8bc73311db1c1 Mon Sep 17 00:00:00 2001 From: Patrick Brouwers Date: Wed, 28 Jun 2017 23:23:54 +0200 Subject: [PATCH] Fix/lifecyclecallbacks (#44) * Remove non-existing lifecycle callbacks * Apply fixes from StyleCI [ci skip] [skip ci] --- .travis.yml | 4 +--- src/Builders/LifecycleEvents.php | 31 +++++++++----------------- tests/Builders/BuilderTest.php | 8 +++---- tests/Builders/LifecycleEventsTest.php | 25 --------------------- 4 files changed, 16 insertions(+), 52 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4bfab5d..0d3bc4f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ php: - 5.5 - 5.6 - 7.0 - - hhvm + - 7.1 before_script: - travis_retry composer self-update @@ -19,6 +19,4 @@ sudo: false script: php vendor/bin/phpunit --coverage-clover=coverage.clover matrix: - allow_failures: - - php: 7.0 fast_finish: true diff --git a/src/Builders/LifecycleEvents.php b/src/Builders/LifecycleEvents.php index fca2c8d..fe0433a 100644 --- a/src/Builders/LifecycleEvents.php +++ b/src/Builders/LifecycleEvents.php @@ -4,6 +4,7 @@ use Doctrine\ORM\Events; use Doctrine\ORM\Mapping\Builder\ClassMetadataBuilder; +use InvalidArgumentException; use LaravelDoctrine\Fluent\Buildable; /** @@ -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 { @@ -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 => [], ]; /** @@ -63,7 +54,7 @@ public function __construct(ClassMetadataBuilder $builder) * @param string $method * @param array $args * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * * @return LifecycleEvents */ @@ -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'); } /** diff --git a/tests/Builders/BuilderTest.php b/tests/Builders/BuilderTest.php index a3af371..70e780f 100644 --- a/tests/Builders/BuilderTest.php +++ b/tests/Builders/BuilderTest.php @@ -657,8 +657,8 @@ 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) { @@ -666,11 +666,11 @@ public function test_events_can_be_configured_through_a_callable() } $this->assertTrue( - $this->fluent->getClassMetadata()->hasLifecycleCallbacks('onClear') + $this->fluent->getClassMetadata()->hasLifecycleCallbacks('preFlush') ); $this->assertTrue( - $this->fluent->getClassMetadata()->hasLifecycleCallbacks('onFlush') + $this->fluent->getClassMetadata()->hasLifecycleCallbacks('postRemove') ); } diff --git a/tests/Builders/LifecycleEventsTest.php b/tests/Builders/LifecycleEventsTest.php index c14a20b..5d4a83c 100644 --- a/tests/Builders/LifecycleEventsTest.php +++ b/tests/Builders/LifecycleEventsTest.php @@ -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);