Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Laravel 11 compatability #111

Merged
merged 4 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ composer.lock
.DS_Store
Thumbs.db
auth.json
.phpunit.cache
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
],
"require": {
"php": "^7.3|^8.0",
"laravel/nova": "^4.0",
"orchestra/testbench": "^8.5"
"laravel/nova": "^4.0"
},
"require-dev": {
"orchestra/testbench": "^8.5",
"phpunit/phpunit": "^10.0"
},
"autoload": {
Expand Down
59 changes: 25 additions & 34 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,35 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="./tests/bootstrap.php"
>
<testsuites>
<testsuite name="Package Test Suite">
<directory suffix=".php">./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>src/</directory>
<exclude>
<directory>src/Exceptions</directory>
<directory>src/Stubs</directory>
<directory>src/Http</directory>
<file>src/config.php</file>
<file>src/NovaPageFacade.php</file>
<file>src/NovaPageRouteMacros.php</file>
<file>src/NovaPageServiceProvider.php</file>
<file>src/NovaPageTool.php</file>
<file>src/NovaPageToolServiceProvider.php</file>
<file>src/Sources/SourceInterface.php</file>
</exclude>
</whitelist>
</filter>
</phpunit>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" cacheDirectory=".phpunit.cache">
<testsuites>
<testsuite name="Package Test Suite">
<directory suffix=".php">./tests/</directory>
<exclude>./tests/test-application/</exclude>
</testsuite>
</testsuites>
<source>
<include>
<directory>src/</directory>
</include>
<exclude>
<directory>src/Exceptions</directory>
<directory>src/Stubs</directory>
<directory>src/Http</directory>
<file>src/config.php</file>
<file>src/NovaPageFacade.php</file>
<file>src/NovaPageRouteMacros.php</file>
<file>src/NovaPageServiceProvider.php</file>
<file>src/NovaPageTool.php</file>
<file>src/NovaPageToolServiceProvider.php</file>
<file>src/Sources/SourceInterface.php</file>
</exclude>
</source>
</phpunit>
8 changes: 4 additions & 4 deletions src/Pages/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ public function __set($attribute, $value)
* @param mixed $offset
* @return bool
*/
public function offsetExists($offset)
public function offsetExists($offset): bool
{
return ! is_null($this->__get($offset));
}
Expand All @@ -422,7 +422,7 @@ public function offsetExists($offset)
* @param mixed $offset
* @return mixed
*/
public function offsetGet($offset)
public function offsetGet($offset): mixed
{
return $this->__get($offset);
}
Expand All @@ -434,7 +434,7 @@ public function offsetGet($offset)
* @param mixed $value
* @return void
*/
public function offsetSet($offset, $value)
public function offsetSet($offset, $value): void
{
$this->__set($offset, $value);
}
Expand All @@ -445,7 +445,7 @@ public function offsetSet($offset, $value)
* @param mixed $offset
* @return void
*/
public function offsetUnset($offset)
public function offsetUnset($offset): void
{
unset($this->attributes[$offset]);
}
Expand Down
37 changes: 20 additions & 17 deletions tests/Unit/Pages/PageResourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
use Whitecube\NovaPage\Pages\PageResource;
use Whitecube\NovaPage\Pages\Template;

class PageResourceTest extends TestCase {

class PageResourceTest extends TestCase
{
protected function getPackageProviders($app)
{
return ['Whitecube\NovaPage\NovaPageServiceProvider'];
Expand Down Expand Up @@ -55,10 +55,6 @@ public function can_get_the_templates_name_as_the_resource_subtitle()
public function can_get_a_fresh_instance_of_the_model_represented_by_the_resource()
{
$this->assertInstanceOf(Manager::class, PageResource::newModel());

$this->expectException(TemplateNotFoundException::class);
request()->resourceId = 'route.test';
PageResource::newModel();
}

/** @test */
Expand All @@ -75,7 +71,8 @@ public function can_get_the_resources_fields_and_adds_default_nova_page_fields()
Text::make('Foo')
]);
$instance = new PageResource($template);
$fields = $instance->fields(request());
$request = NovaRequest::createFromBase(request());
$fields = $instance->fields($request);
$this->assertCount(2, $fields);
$this->assertInstanceOf(Panel::class, $fields[0]);
$this->assertInstanceOf(Text::class, $fields[1]);
Expand All @@ -89,7 +86,8 @@ public function can_get_the_resources_cards()
'Test\Cards\TestCard'
]);
$instance = new PageResource($template);
$cards = $instance->cards(request());
$request = NovaRequest::createFromBase(request());
$cards = $instance->cards($request);
$this->assertCount(1, $cards);
$this->assertSame('Test\Cards\TestCard', $cards[0]);
}
Expand All @@ -99,37 +97,42 @@ public function returns_no_filters()
{
$template = $this->createMock(Template::class);
$instance = new PageResource($template);
$this->assertCount(0, $instance->filters(request()));
$request = NovaRequest::createFromBase(request());
$this->assertCount(0, $instance->filters($request));
}

/** @test */
public function returns_no_lenses()
{
$template = $this->createMock(Template::class);
$instance = new PageResource($template);
$this->assertCount(0, $instance->lenses(request()));
$request = NovaRequest::createFromBase(request());
$this->assertCount(0, $instance->lenses($request));
}

/** @test */
public function returns_no_actions()
{
$template = $this->createMock(Template::class);
$instance = new PageResource($template);
$this->assertCount(0, $instance->actions(request()));
$request = NovaRequest::createFromBase(request());
$this->assertCount(0, $instance->actions($request));
}

/** @test */
public function does_not_allow_creation()
{
$this->assertFalse(PageResource::authorizedToCreate(request()));
$request = NovaRequest::createFromBase(request());
$this->assertFalse(PageResource::authorizedToCreate($request));
}

/** @test */
public function does_not_allow_deletion()
{
$template = $this->createMock(Template::class);
$instance = new PageResource($template);
$this->assertFalse($instance->authorizedToDelete(request()));
$request = NovaRequest::createFromBase(request());
$this->assertFalse($instance->authorizedToDelete($request));
}

/** @test */
Expand All @@ -140,9 +143,9 @@ public function can_prepare_the_resource_to_be_json_serialized()
'controller' => ResourceIndexController::class . '@handle'
]);

$this->app->bind(NovaRequest::class, function() use ($route) {
$this->app->bind(NovaRequest::class, function () use ($route) {
return new class ($route) extends NovaRequest {
public function __construct($route)
public function __construct($route)
{
$this->routeMock = $route;
}
Expand All @@ -159,9 +162,9 @@ public function route($param = null, $default = null)
$instance = new PageResource($template);

$result = $instance->jsonSerialize();

$this->assertTrue(is_array($result));
$this->assertArrayHasKey('fields', $result);
}

}
}
5 changes: 0 additions & 5 deletions tests/bootstrap.php

This file was deleted.

2 changes: 1 addition & 1 deletion tests/test-application/resources/lang/route/test.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"title": "Test page title",
"created_at": "2019-02-18 08:48:00",
"updated_at": "2023-04-25 08:10:01",
"updated_at": "2024-06-18 13:10:18",
"attributes": {
"test_field": "Test value",
"foo_json": {
Expand Down