Skip to content

Commit 096913c

Browse files
authoredFeb 20, 2024·
Added return type for model ast visitors. (#6544)
1 parent e1bd657 commit 096913c

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed
 

‎tests/Cases/ElasticsearchEngineTest.php

+7
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Hyperf\Database\Model\Model;
1616
use Hyperf\Scout\Builder;
1717
use Hyperf\Scout\Engine\ElasticsearchEngine;
18+
use HyperfTest\Scout\Stub\ContainerStub;
1819
use HyperfTest\Scout\Stub\ElasticsearchEngineTestModel;
1920
use HyperfTest\Scout\Stub\SearchableModel;
2021
use Mockery;
@@ -28,10 +29,16 @@
2829
#[CoversNothing]
2930
class ElasticsearchEngineTest extends TestCase
3031
{
32+
protected function setUp(): void
33+
{
34+
ContainerStub::mockContainer();
35+
}
36+
3137
protected function tearDown(): void
3238
{
3339
Mockery::close();
3440
$this->assertTrue(true);
41+
ContainerStub::unsetContainer();
3542
}
3643

3744
public function testUpdateAddsObjectsToIndex()

‎tests/Cases/SearchableTest.php

+7
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
*/
1212
namespace HyperfTest\Scout\Cases;
1313

14+
use HyperfTest\Scout\Stub\ContainerStub;
1415
use HyperfTest\Scout\Stub\ModelStubForMakeAllSearchable;
1516
use HyperfTest\Scout\Stub\SearchableModel;
1617
use Mockery as m;
@@ -24,10 +25,16 @@
2425
#[CoversNothing]
2526
class SearchableTest extends TestCase
2627
{
28+
protected function setUp(): void
29+
{
30+
ContainerStub::mockContainer();
31+
}
32+
2733
protected function tearDown(): void
2834
{
2935
m::close();
3036
$this->assertTrue(true);
37+
ContainerStub::unsetContainer();
3138
}
3239

3340
public function testSearchableUsingUpdateIsCalledOnCollection()

‎tests/Stub/ContainerStub.php

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
}

0 commit comments

Comments
 (0)
Please sign in to comment.