File tree 3 files changed +53
-0
lines changed
3 files changed +53
-0
lines changed Original file line number Diff line number Diff line change 15
15
use Hyperf \Database \Model \Model ;
16
16
use Hyperf \Scout \Builder ;
17
17
use Hyperf \Scout \Engine \ElasticsearchEngine ;
18
+ use HyperfTest \Scout \Stub \ContainerStub ;
18
19
use HyperfTest \Scout \Stub \ElasticsearchEngineTestModel ;
19
20
use HyperfTest \Scout \Stub \SearchableModel ;
20
21
use Mockery ;
28
29
#[CoversNothing]
29
30
class ElasticsearchEngineTest extends TestCase
30
31
{
32
+ protected function setUp (): void
33
+ {
34
+ ContainerStub::mockContainer ();
35
+ }
36
+
31
37
protected function tearDown (): void
32
38
{
33
39
Mockery::close ();
34
40
$ this ->assertTrue (true );
41
+ ContainerStub::unsetContainer ();
35
42
}
36
43
37
44
public function testUpdateAddsObjectsToIndex ()
Original file line number Diff line number Diff line change 11
11
*/
12
12
namespace HyperfTest \Scout \Cases ;
13
13
14
+ use HyperfTest \Scout \Stub \ContainerStub ;
14
15
use HyperfTest \Scout \Stub \ModelStubForMakeAllSearchable ;
15
16
use HyperfTest \Scout \Stub \SearchableModel ;
16
17
use Mockery as m ;
24
25
#[CoversNothing]
25
26
class SearchableTest extends TestCase
26
27
{
28
+ protected function setUp (): void
29
+ {
30
+ ContainerStub::mockContainer ();
31
+ }
32
+
27
33
protected function tearDown (): void
28
34
{
29
35
m::close ();
30
36
$ this ->assertTrue (true );
37
+ ContainerStub::unsetContainer ();
31
38
}
32
39
33
40
public function testSearchableUsingUpdateIsCalledOnCollection ()
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+ /**
5
+ * This file is part of Hyperf.
6
+ *
7
+ * @link https://www.hyperf.io
8
+ * @document https://hyperf.wiki
9
+ * @contact group@hyperf.io
10
+ * @license https://github.com/hyperf/hyperf/blob/master/LICENSE
11
+ */
12
+ namespace HyperfTest \Scout \Stub ;
13
+
14
+ use Hyperf \Context \ApplicationContext ;
15
+ use Hyperf \Database \Model \Register ;
16
+ use Hyperf \Scout \ModelObserver ;
17
+ use Mockery ;
18
+ use Psr \Container \ContainerInterface ;
19
+ use ReflectionClass ;
20
+
21
+ class ContainerStub
22
+ {
23
+ public static function unsetContainer (): void
24
+ {
25
+ $ ref = new ReflectionClass (ApplicationContext::class);
26
+ $ c = $ ref ->getProperty ('container ' );
27
+ $ c ->setValue (null );
28
+ }
29
+
30
+ public static function mockContainer ()
31
+ {
32
+ $ container = Mockery::mock (ContainerInterface::class);
33
+ $ container ->shouldReceive ('get ' )->with (ModelObserver::class)->andReturn (new ModelObserver ());
34
+
35
+ ApplicationContext::setContainer ($ container );
36
+
37
+ Register::unsetEventDispatcher ();
38
+ }
39
+ }
You can’t perform that action at this time.
0 commit comments