Skip to content

Commit

Permalink
update to laravel 10
Browse files Browse the repository at this point in the history
  • Loading branch information
roman.zoria authored and endihunter committed Jun 7, 2023
1 parent ab45174 commit e2ebecf
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 101 deletions.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
"spatie/once": "^2.0"
},
"require-dev": {
"phpunit/phpunit": "^9.6",
"phpunit/phpunit": "^10.0",
"mockery/mockery": "^1.5",
"laravel/framework": "^9.0",
"laravel/laravel": "^9.0"
"laravel/framework": "^10.0",
"laravel/laravel": "^10.0"
},
"autoload": {
"psr-4": {
Expand Down
40 changes: 15 additions & 25 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,27 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="tests/bootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
stopOnError="false"
processIsolation="false"
stopOnFailure="false"
verbose="true"
>
<testsuites>
<testsuite name="AdminArchitect Core Test Suite">
<directory suffix="Test.php">./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
<exclude>
<directory suffix=".blade.php">./src/</directory>
</exclude>
</whitelist>
</filter>
<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">
<coverage/>
<testsuites>
<testsuite name="AdminArchitect Core Test Suite">
<directory suffix="Test.php">./tests/</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
<exclude>
<directory suffix=".blade.php">./src/</directory>
</exclude>
</source>
</phpunit>
6 changes: 5 additions & 1 deletion tests/Actions/SaveOrderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ public function it_calls_eloquent_method()
$request = $this->createMock(Request::class);
$request->expects($this->once())->method('get')->with('rank')->willReturn([]);

$eloquent = $this->createPartialMock(User::class, ['syncRanking', 'getRankableColumn']);
$eloquent = $this->getMockBuilder(User::class)
->disableOriginalConstructor()
->addMethods(['syncRanking', 'getRankableColumn'])
->getMock();

$eloquent->expects($this->once())->method('syncRanking')->with([]);
$eloquent->expects($this->once())->method('getRankableColumn')->willReturn('rank');

Expand Down
13 changes: 11 additions & 2 deletions tests/Auth/SuperAdminRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ public function it_fetches_user()
$guard = $this->createMock(SessionGuard::class);
$guard->expects($this->once())->method('user');

$auth = $this->createPartialMock(Factory::class, ['user', 'guard', 'shouldUse']);
$auth = $this->getMockBuilder(Factory::class)
->disableOriginalConstructor()
->onlyMethods(['guard', 'shouldUse'])
->addMethods(['user'])
->getMock();

$auth->expects($this->once())->method('guard')->with('admin')->willReturn($guard);

app()->instance('Illuminate\Contracts\Auth\Factory', $auth);
Expand All @@ -42,7 +47,11 @@ public function it_returns_false_if_no_auth_user()
public function it_calls_a_model_super_admin_method()
{
/** @var Authenticatable|MockObject $user */
$user = $this->createPartialMock(User::class, ['isSuperAdmin']);
$user = $this->getMockBuilder(User::class)
->disableOriginalConstructor()
->addMethods(['isSuperAdmin'])
->getMock();

$user->expects($this->once())
->method('isSuperAdmin')
->willReturn(true);
Expand Down
34 changes: 15 additions & 19 deletions tests/Controllers/AdminControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use PHPUnit\Framework\MockObject\MockObject;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Terranet\Administrator\ActionsManager;
use Terranet\Administrator\Contracts\Module;
use Terranet\Administrator\Controllers\AdminController;
use Terranet\Administrator\Middleware\Authenticate;
use Terranet\Administrator\Middleware\AuthProvider;
Expand All @@ -23,7 +22,7 @@ class AdminControllerTest extends CoreTestCase
public function it_sets_required_middleware()
{
$controller = $this->getMockBuilder(AdminController::class)
->setMethods(['middleware'])
->onlyMethods(['middleware'])
->disableOriginalConstructor()
->getMock();

Expand All @@ -43,7 +42,7 @@ public function it_authorizes_the_action_call()
{
/** @var AdminController|MockObject $controller */
$controller = $this->getMockBuilder(AdminController::class)
->setMethods(null)
->onlyMethods([])
->setConstructorArgs([$this->mockTranslator()])
->getMock();

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

/** @var AdminController|MockObject $controller */
$controller = $this->getMockBuilder(AdminController::class)
->setMethods(null)
->onlyMethods([])
->setConstructorArgs([$translator])
->getMock();

Expand All @@ -94,13 +93,13 @@ public function it_redirects_back_to_provided_url()
{
/** @var AdminController|MockObject $controller */
$controller = $this->getMockBuilder(AdminController::class)
->setMethods(null)
->onlyMethods([])
->setConstructorArgs([$this->mockTranslator()])
->getMock();

$request = $this->getMockBuilder(Request::class)
->disableOriginalConstructor()
->setMethods(['get'])
->onlyMethods(['get'])
->disableAutoload()
->getMock();

Expand All @@ -124,13 +123,13 @@ public function it_redirects_back_to_editable_model()
{
/** @var AdminController|MockObject $controller */
$controller = $this->getMockBuilder(AdminController::class)
->setMethods([])
->onlyMethods([])
->setConstructorArgs([$this->mockTranslator()])
->getMock();

$request = $this->getMockBuilder(Request::class)
->disableOriginalConstructor()
->setMethods(['get', 'exists'])
->onlyMethods(['get', 'exists'])
->disableAutoload()
->getMock();

Expand Down Expand Up @@ -164,24 +163,21 @@ public function it_redirects_back_to_index_table()

$request = $this->getMockBuilder(Request::class)
->disableOriginalConstructor()
->setMethods(['get', 'exists'])
->onlyMethods(['get', 'exists'])
->disableAutoload()
->getMock();

$request->expects($this->at(0))
$request->expects($this->exactly(1))
->method('get')
->with('back_to')
->willReturn(null);

$request->expects($this->at(1))
->method('exists')
->with('save')
->willReturn(false);

$request->expects($this->at(2))
->method('exists')
->with('save_return')
->willReturn(true);
$request->expects($this->exactly(2))
->method('exists')
->willReturnCallback(fn($param) => match ($param) {
'save' => false,
'save_return' => true,
});

$redirector = $this->createMock(Redirector::class);
$redirector->expects($this->once())
Expand Down
91 changes: 40 additions & 51 deletions tests/Controllers/AuthControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ class AuthControllerTest extends CoreTestCase
public function setUp(): void
{
$this->controller = $this->getMockBuilder(AuthController::class)
->disableOriginalConstructor()
->disableOriginalClone()
->setMethods(['guard'])
->getMock();
->disableOriginalConstructor()
->disableOriginalClone()
->onlyMethods(['guard'])
->getMock();

$this->guard = $this->getMockBuilder(SessionGuard::class)
->disableOriginalConstructor()
->setMethods(['attempt', 'logout'])
->getMock();
->disableOriginalConstructor()
->onlyMethods(['attempt', 'logout'])
->getMock();

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

Expand All @@ -59,21 +59,15 @@ public function it_logs_in_the_user()
{
$config = $this->createMock(Repository::class);
$config->expects($this->exactly(4))
->method('get')
->withConsecutive(
['auth.identity', 'username'],
['auth.credential', 'password'],
['auth.conditions', []],
['home_page']
)
->willReturn(
'username',
'password',
['active' => true],
function () {
return '/home';
}
);
->method('get')
->willReturnCallback(fn($key, $default) => match ([$key, $default]) {
['auth.identity', 'username'] => 'username',
['auth.credential', 'password'] => 'password',
['auth.conditions', []] => ['active' => true],
['home_page', null] => function () {
return '/home';
}
});

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

$request->expects($this->once())
->method('only')
->with(['username', 'password'])
->willReturn($credentials);
->method('only')
->with(['username', 'password'])
->willReturn($credentials);
$request->expects($this->once())
->method('get')
->with('remember_me', 0)
->willReturn(1);
->method('get')
->with('remember_me', 0)
->willReturn(1);

$this->guard->expects($this->once())
->method('attempt')
->with($credentials + ['active' => true], 1, true)
->willReturn(true);
->method('attempt')
->with($credentials + ['active' => true], 1, true)
->willReturn(true);

URL::shouldReceive('to')->with('/home')->andReturn(null);
Redirect::shouldReceive('to')->with(null);
Expand All @@ -109,17 +103,12 @@ public function it_redirects_back_when_login_failed()
{
$config = $this->createMock(Repository::class);
$config->expects($this->exactly(3))
->method('get')
->withConsecutive(
['auth.identity', 'username'],
['auth.credential', 'password'],
['auth.conditions', []]
)
->willReturn(
'username',
'password',
['active' => true]
);
->method('get')
->willReturnCallback(fn($key, $default) => match ([$key, $default]) {
['auth.identity', 'username'] => 'username',
['auth.credential', 'password'] => 'password',
['auth.conditions', []] => ['active' => true],
});

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

$request->expects($this->once())
->method('only')
->with(['username', 'password'])
->willReturn($credentials);
->method('only')
->with(['username', 'password'])
->willReturn($credentials);
$request->expects($this->once())
->method('get')
->with('remember_me', 0)
->willReturn(1);
->method('get')
->with('remember_me', 0)
->willReturn(1);

$this->guard->expects($this->once())
->method('attempt')
->with($credentials + ['active' => true], 1, true)
->willReturn(false);
->method('attempt')
->with($credentials + ['active' => true], 1, true)
->willReturn(false);

$translator = $this->mockTranslator();
$translator->shouldReceive('get')->andReturn('error');
Expand Down

0 comments on commit e2ebecf

Please sign in to comment.