Skip to content

Commit e2ebecf

Browse files
roman.zoriaendihunter
authored andcommitted
update to laravel 10
1 parent ab45174 commit e2ebecf

File tree

6 files changed

+89
-101
lines changed

6 files changed

+89
-101
lines changed

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
"spatie/once": "^2.0"
2525
},
2626
"require-dev": {
27-
"phpunit/phpunit": "^9.6",
27+
"phpunit/phpunit": "^10.0",
2828
"mockery/mockery": "^1.5",
29-
"laravel/framework": "^9.0",
30-
"laravel/laravel": "^9.0"
29+
"laravel/framework": "^10.0",
30+
"laravel/laravel": "^10.0"
3131
},
3232
"autoload": {
3333
"psr-4": {

phpunit.xml

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,17 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit backupGlobals="false"
3-
backupStaticAttributes="false"
4-
bootstrap="tests/bootstrap.php"
5-
colors="true"
6-
convertErrorsToExceptions="true"
7-
convertNoticesToExceptions="true"
8-
convertWarningsToExceptions="true"
9-
stopOnError="false"
10-
processIsolation="false"
11-
stopOnFailure="false"
12-
verbose="true"
13-
>
14-
<testsuites>
15-
<testsuite name="AdminArchitect Core Test Suite">
16-
<directory suffix="Test.php">./tests/</directory>
17-
</testsuite>
18-
</testsuites>
19-
<filter>
20-
<whitelist processUncoveredFilesFromWhitelist="true">
21-
<directory suffix=".php">./src</directory>
22-
<exclude>
23-
<directory suffix=".blade.php">./src/</directory>
24-
</exclude>
25-
</whitelist>
26-
</filter>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" bootstrap="tests/bootstrap.php" colors="true" stopOnError="false" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.1/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
3+
<coverage/>
4+
<testsuites>
5+
<testsuite name="AdminArchitect Core Test Suite">
6+
<directory suffix="Test.php">./tests/</directory>
7+
</testsuite>
8+
</testsuites>
9+
<source>
10+
<include>
11+
<directory suffix=".php">./src</directory>
12+
</include>
13+
<exclude>
14+
<directory suffix=".blade.php">./src/</directory>
15+
</exclude>
16+
</source>
2717
</phpunit>

tests/Actions/SaveOrderTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ public function it_calls_eloquent_method()
1717
$request = $this->createMock(Request::class);
1818
$request->expects($this->once())->method('get')->with('rank')->willReturn([]);
1919

20-
$eloquent = $this->createPartialMock(User::class, ['syncRanking', 'getRankableColumn']);
20+
$eloquent = $this->getMockBuilder(User::class)
21+
->disableOriginalConstructor()
22+
->addMethods(['syncRanking', 'getRankableColumn'])
23+
->getMock();
24+
2125
$eloquent->expects($this->once())->method('syncRanking')->with([]);
2226
$eloquent->expects($this->once())->method('getRankableColumn')->willReturn('rank');
2327

tests/Auth/SuperAdminRuleTest.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ public function it_fetches_user()
2020
$guard = $this->createMock(SessionGuard::class);
2121
$guard->expects($this->once())->method('user');
2222

23-
$auth = $this->createPartialMock(Factory::class, ['user', 'guard', 'shouldUse']);
23+
$auth = $this->getMockBuilder(Factory::class)
24+
->disableOriginalConstructor()
25+
->onlyMethods(['guard', 'shouldUse'])
26+
->addMethods(['user'])
27+
->getMock();
28+
2429
$auth->expects($this->once())->method('guard')->with('admin')->willReturn($guard);
2530

2631
app()->instance('Illuminate\Contracts\Auth\Factory', $auth);
@@ -42,7 +47,11 @@ public function it_returns_false_if_no_auth_user()
4247
public function it_calls_a_model_super_admin_method()
4348
{
4449
/** @var Authenticatable|MockObject $user */
45-
$user = $this->createPartialMock(User::class, ['isSuperAdmin']);
50+
$user = $this->getMockBuilder(User::class)
51+
->disableOriginalConstructor()
52+
->addMethods(['isSuperAdmin'])
53+
->getMock();
54+
4655
$user->expects($this->once())
4756
->method('isSuperAdmin')
4857
->willReturn(true);

tests/Controllers/AdminControllerTest.php

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use PHPUnit\Framework\MockObject\MockObject;
88
use Symfony\Component\HttpKernel\Exception\HttpException;
99
use Terranet\Administrator\ActionsManager;
10-
use Terranet\Administrator\Contracts\Module;
1110
use Terranet\Administrator\Controllers\AdminController;
1211
use Terranet\Administrator\Middleware\Authenticate;
1312
use Terranet\Administrator\Middleware\AuthProvider;
@@ -23,7 +22,7 @@ class AdminControllerTest extends CoreTestCase
2322
public function it_sets_required_middleware()
2423
{
2524
$controller = $this->getMockBuilder(AdminController::class)
26-
->setMethods(['middleware'])
25+
->onlyMethods(['middleware'])
2726
->disableOriginalConstructor()
2827
->getMock();
2928

@@ -43,7 +42,7 @@ public function it_authorizes_the_action_call()
4342
{
4443
/** @var AdminController|MockObject $controller */
4544
$controller = $this->getMockBuilder(AdminController::class)
46-
->setMethods(null)
45+
->onlyMethods([])
4746
->setConstructorArgs([$this->mockTranslator()])
4847
->getMock();
4948

@@ -70,7 +69,7 @@ public function it_throw_unauthorized_exception()
7069

7170
/** @var AdminController|MockObject $controller */
7271
$controller = $this->getMockBuilder(AdminController::class)
73-
->setMethods(null)
72+
->onlyMethods([])
7473
->setConstructorArgs([$translator])
7574
->getMock();
7675

@@ -94,13 +93,13 @@ public function it_redirects_back_to_provided_url()
9493
{
9594
/** @var AdminController|MockObject $controller */
9695
$controller = $this->getMockBuilder(AdminController::class)
97-
->setMethods(null)
96+
->onlyMethods([])
9897
->setConstructorArgs([$this->mockTranslator()])
9998
->getMock();
10099

101100
$request = $this->getMockBuilder(Request::class)
102101
->disableOriginalConstructor()
103-
->setMethods(['get'])
102+
->onlyMethods(['get'])
104103
->disableAutoload()
105104
->getMock();
106105

@@ -124,13 +123,13 @@ public function it_redirects_back_to_editable_model()
124123
{
125124
/** @var AdminController|MockObject $controller */
126125
$controller = $this->getMockBuilder(AdminController::class)
127-
->setMethods([])
126+
->onlyMethods([])
128127
->setConstructorArgs([$this->mockTranslator()])
129128
->getMock();
130129

131130
$request = $this->getMockBuilder(Request::class)
132131
->disableOriginalConstructor()
133-
->setMethods(['get', 'exists'])
132+
->onlyMethods(['get', 'exists'])
134133
->disableAutoload()
135134
->getMock();
136135

@@ -164,24 +163,21 @@ public function it_redirects_back_to_index_table()
164163

165164
$request = $this->getMockBuilder(Request::class)
166165
->disableOriginalConstructor()
167-
->setMethods(['get', 'exists'])
166+
->onlyMethods(['get', 'exists'])
168167
->disableAutoload()
169168
->getMock();
170169

171-
$request->expects($this->at(0))
170+
$request->expects($this->exactly(1))
172171
->method('get')
173172
->with('back_to')
174173
->willReturn(null);
175174

176-
$request->expects($this->at(1))
177-
->method('exists')
178-
->with('save')
179-
->willReturn(false);
180-
181-
$request->expects($this->at(2))
182-
->method('exists')
183-
->with('save_return')
184-
->willReturn(true);
175+
$request->expects($this->exactly(2))
176+
->method('exists')
177+
->willReturnCallback(fn($param) => match ($param) {
178+
'save' => false,
179+
'save_return' => true,
180+
});
185181

186182
$redirector = $this->createMock(Redirector::class);
187183
$redirector->expects($this->once())

tests/Controllers/AuthControllerTest.php

Lines changed: 40 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ class AuthControllerTest extends CoreTestCase
2828
public function setUp(): void
2929
{
3030
$this->controller = $this->getMockBuilder(AuthController::class)
31-
->disableOriginalConstructor()
32-
->disableOriginalClone()
33-
->setMethods(['guard'])
34-
->getMock();
31+
->disableOriginalConstructor()
32+
->disableOriginalClone()
33+
->onlyMethods(['guard'])
34+
->getMock();
3535

3636
$this->guard = $this->getMockBuilder(SessionGuard::class)
37-
->disableOriginalConstructor()
38-
->setMethods(['attempt', 'logout'])
39-
->getMock();
37+
->disableOriginalConstructor()
38+
->onlyMethods(['attempt', 'logout'])
39+
->getMock();
4040

4141
$this->controller->method('guard')->willReturn($this->guard);
4242

@@ -59,21 +59,15 @@ public function it_logs_in_the_user()
5959
{
6060
$config = $this->createMock(Repository::class);
6161
$config->expects($this->exactly(4))
62-
->method('get')
63-
->withConsecutive(
64-
['auth.identity', 'username'],
65-
['auth.credential', 'password'],
66-
['auth.conditions', []],
67-
['home_page']
68-
)
69-
->willReturn(
70-
'username',
71-
'password',
72-
['active' => true],
73-
function () {
74-
return '/home';
75-
}
76-
);
62+
->method('get')
63+
->willReturnCallback(fn($key, $default) => match ([$key, $default]) {
64+
['auth.identity', 'username'] => 'username',
65+
['auth.credential', 'password'] => 'password',
66+
['auth.conditions', []] => ['active' => true],
67+
['home_page', null] => function () {
68+
return '/home';
69+
}
70+
});
7771

7872
/** @var LoginRequest|MockObject $request */
7973
$request = $this->createMock(LoginRequest::class);
@@ -83,18 +77,18 @@ function () {
8377
];
8478

8579
$request->expects($this->once())
86-
->method('only')
87-
->with(['username', 'password'])
88-
->willReturn($credentials);
80+
->method('only')
81+
->with(['username', 'password'])
82+
->willReturn($credentials);
8983
$request->expects($this->once())
90-
->method('get')
91-
->with('remember_me', 0)
92-
->willReturn(1);
84+
->method('get')
85+
->with('remember_me', 0)
86+
->willReturn(1);
9387

9488
$this->guard->expects($this->once())
95-
->method('attempt')
96-
->with($credentials + ['active' => true], 1, true)
97-
->willReturn(true);
89+
->method('attempt')
90+
->with($credentials + ['active' => true], 1, true)
91+
->willReturn(true);
9892

9993
URL::shouldReceive('to')->with('/home')->andReturn(null);
10094
Redirect::shouldReceive('to')->with(null);
@@ -109,17 +103,12 @@ public function it_redirects_back_when_login_failed()
109103
{
110104
$config = $this->createMock(Repository::class);
111105
$config->expects($this->exactly(3))
112-
->method('get')
113-
->withConsecutive(
114-
['auth.identity', 'username'],
115-
['auth.credential', 'password'],
116-
['auth.conditions', []]
117-
)
118-
->willReturn(
119-
'username',
120-
'password',
121-
['active' => true]
122-
);
106+
->method('get')
107+
->willReturnCallback(fn($key, $default) => match ([$key, $default]) {
108+
['auth.identity', 'username'] => 'username',
109+
['auth.credential', 'password'] => 'password',
110+
['auth.conditions', []] => ['active' => true],
111+
});
123112

124113
/** @var LoginRequest|MockObject $request */
125114
$request = $this->createMock(LoginRequest::class);
@@ -129,18 +118,18 @@ public function it_redirects_back_when_login_failed()
129118
];
130119

131120
$request->expects($this->once())
132-
->method('only')
133-
->with(['username', 'password'])
134-
->willReturn($credentials);
121+
->method('only')
122+
->with(['username', 'password'])
123+
->willReturn($credentials);
135124
$request->expects($this->once())
136-
->method('get')
137-
->with('remember_me', 0)
138-
->willReturn(1);
125+
->method('get')
126+
->with('remember_me', 0)
127+
->willReturn(1);
139128

140129
$this->guard->expects($this->once())
141-
->method('attempt')
142-
->with($credentials + ['active' => true], 1, true)
143-
->willReturn(false);
130+
->method('attempt')
131+
->with($credentials + ['active' => true], 1, true)
132+
->willReturn(false);
144133

145134
$translator = $this->mockTranslator();
146135
$translator->shouldReceive('get')->andReturn('error');

0 commit comments

Comments
 (0)