Skip to content

Commit 2476612

Browse files
Fix/lifecyclecallbacks (#44)
* Remove non-existing lifecycle callbacks * Apply fixes from StyleCI [ci skip] [skip ci]
1 parent 5724dcd commit 2476612

File tree

4 files changed

+16
-52
lines changed

4 files changed

+16
-52
lines changed

.travis.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ php:
44
- 5.5
55
- 5.6
66
- 7.0
7-
- hhvm
7+
- 7.1
88

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

2121
matrix:
22-
allow_failures:
23-
- php: 7.0
2422
fast_finish: true

src/Builders/LifecycleEvents.php

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Doctrine\ORM\Events;
66
use Doctrine\ORM\Mapping\Builder\ClassMetadataBuilder;
7+
use InvalidArgumentException;
78
use LaravelDoctrine\Fluent\Buildable;
89

910
/**
@@ -14,12 +15,7 @@
1415
* @method LifecycleEvents preUpdate(string $method)
1516
* @method LifecycleEvents postUpdate(string $method)
1617
* @method LifecycleEvents postLoad(string $method)
17-
* @method LifecycleEvents loadClassMetadata(string $method)
18-
* @method LifecycleEvents onClassMetadataNotFound(string $method)
1918
* @method LifecycleEvents preFlush(string $method)
20-
* @method LifecycleEvents onFlush(string $method)
21-
* @method LifecycleEvents postFlush(string $method)
22-
* @method LifecycleEvents onClear(string $method)
2319
*/
2420
class LifecycleEvents implements Buildable
2521
{
@@ -32,19 +28,14 @@ class LifecycleEvents implements Buildable
3228
* @var array
3329
*/
3430
private $events = [
35-
Events::preRemove => [],
36-
Events::postRemove => [],
37-
Events::prePersist => [],
38-
Events::postPersist => [],
39-
Events::preUpdate => [],
40-
Events::postUpdate => [],
41-
Events::postLoad => [],
42-
Events::loadClassMetadata => [],
43-
Events::onClassMetadataNotFound => [],
44-
Events::preFlush => [],
45-
Events::onFlush => [],
46-
Events::postFlush => [],
47-
Events::onClear => [],
31+
Events::preRemove => [],
32+
Events::postRemove => [],
33+
Events::prePersist => [],
34+
Events::postPersist => [],
35+
Events::preUpdate => [],
36+
Events::postUpdate => [],
37+
Events::postLoad => [],
38+
Events::preFlush => [],
4839
];
4940

5041
/**
@@ -63,7 +54,7 @@ public function __construct(ClassMetadataBuilder $builder)
6354
* @param string $method
6455
* @param array $args
6556
*
66-
* @throws \InvalidArgumentException
57+
* @throws InvalidArgumentException
6758
*
6859
* @return LifecycleEvents
6960
*/
@@ -75,7 +66,7 @@ public function __call($method, $args)
7566
return call_user_func_array([$this, 'add'], $args);
7667
}
7768

78-
throw new \InvalidArgumentException('Fluent builder method ['.$method.'] does not exist');
69+
throw new InvalidArgumentException('Fluent builder method ['.$method.'] does not exist');
7970
}
8071

8172
/**

tests/Builders/BuilderTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -657,20 +657,20 @@ public function test_events_can_be_associated_to_the_entity()
657657
public function test_events_can_be_configured_through_a_callable()
658658
{
659659
$this->fluent->events(function (LifecycleEvents $events) {
660-
$events->onClear('swipeFloor');
661-
$events->onFlush('cleanToilet');
660+
$events->preFlush('swipeFloor');
661+
$events->postRemove('cleanToilet');
662662
});
663663

664664
foreach ($this->fluent->getQueued() as $buildable) {
665665
$buildable->build();
666666
}
667667

668668
$this->assertTrue(
669-
$this->fluent->getClassMetadata()->hasLifecycleCallbacks('onClear')
669+
$this->fluent->getClassMetadata()->hasLifecycleCallbacks('preFlush')
670670
);
671671

672672
$this->assertTrue(
673-
$this->fluent->getClassMetadata()->hasLifecycleCallbacks('onFlush')
673+
$this->fluent->getClassMetadata()->hasLifecycleCallbacks('postRemove')
674674
);
675675
}
676676

tests/Builders/LifecycleEventsTest.php

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -64,36 +64,11 @@ public function test_post_load_event()
6464
$this->doEventTest(Events::postLoad);
6565
}
6666

67-
public function test_load_class_metadata_event()
68-
{
69-
$this->doEventTest(Events::loadClassMetadata);
70-
}
71-
72-
public function test_on_class_metadata_not_found_event()
73-
{
74-
$this->doEventTest(Events::onClassMetadataNotFound);
75-
}
76-
7767
public function test_pre_flush_event()
7868
{
7969
$this->doEventTest(Events::preFlush);
8070
}
8171

82-
public function test_on_flush_event()
83-
{
84-
$this->doEventTest(Events::onFlush);
85-
}
86-
87-
public function test_post_flush_event()
88-
{
89-
$this->doEventTest(Events::postFlush);
90-
}
91-
92-
public function test_on_clear_event()
93-
{
94-
$this->doEventTest(Events::onClear);
95-
}
96-
9772
public function test_fluent_builder_method_should_exist()
9873
{
9974
$this->setExpectedException(\InvalidArgumentException::class);

0 commit comments

Comments
 (0)