Skip to content

Commit

Permalink
chore: update test scripts for improved test coverage
Browse files Browse the repository at this point in the history
Signed-off-by: Sam Poyigi <[email protected]>
  • Loading branch information
sampoyigi committed Jan 25, 2025
1 parent 2949f26 commit 8ee2bcf
Show file tree
Hide file tree
Showing 218 changed files with 16,701 additions and 1,002 deletions.
9 changes: 5 additions & 4 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
includes:
- ./vendor/larastan/larastan/extension.neon
- phpstan-baseline.neon

parameters:
level: 5
paths:
- src/
- config/
- database/
- resources/
- src
- config
- database
- resources
treatPhpDocTypesAsCertain: false
# ignoreErrors:
# - '#PHPDoc tag @var#'
Expand Down
15 changes: 9 additions & 6 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
backupGlobals="false"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
processIsolation="false"
stopOnFailure="false"
cacheDirectory=".phpunit.cache"
backupStaticProperties="false">
>
<testsuites>
<testsuite name="Tests">
<directory suffix="Test.php">./tests</directory>
<directory>tests</directory>
</testsuite>
</testsuites>
<coverage/>
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
</source>
<php>
<env name="APP_ENV" value="testing"/>
<env name="APP_DEBUG" value="true"/>
Expand Down
15 changes: 15 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictNewArrayRector;

return RectorConfig::configure()
->withPaths([__DIR__.'/src', __DIR__.'/tests'])
->withSkip([
ReturnTypeFromStrictNewArrayRector::class,
])
->withTypeCoverageLevel(1)
->withDeadCodeLevel(0)
->withCodeQualityLevel(0);
18 changes: 8 additions & 10 deletions tests/Pest.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
<?php

use Illuminate\Http\Request;
use Illuminate\Routing\Route;
use Igniter\User\Models\User;

uses(Igniter\Tests\TestCase::class)->in(__DIR__.'/src');

pest()->group('admin')->in('src/Admin');
pest()->group('main')->in('src/Main');
pest()->group('system')->in('src/System');
pest()->group('flame')->in('src/Flame');

function testThemePath()
{
return realpath(__DIR__.'/resources/themes/tests-theme');
}

function createRequest($uri, $routeName)
function actingAsSuperUser()
{
$request = new Request([], [], [], [], [], ['REQUEST_URI' => $uri]);

$request->setRouteResolver(function() use ($uri, $routeName, $request) {
return (new Route('GET', $uri, ['as' => $routeName]))->bind($request);
});

return $request;
return test()->actingAs(User::factory()->superUser()->create(), 'igniter-admin');
}
Empty file added tests/resources/css/style.css
Empty file.
Empty file added tests/resources/js/script.js
Empty file.
14 changes: 14 additions & 0 deletions tests/resources/models/test_settings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

return [
'form' => [
'toolbar' => [],
'fields' => [
'name' => [
'label' => 'Name',
'type' => 'text',
'span' => 'left',
],
],
],
];
4 changes: 4 additions & 0 deletions tests/resources/scss/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
body {
background-color: #f00;
color: #fff;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is a test content
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
name: Default Layout

'[testComponentWithLifecycle]':
---
<html>
<body>

@themePage

</body>
</html>
12 changes: 12 additions & 0 deletions tests/resources/themes/tests-theme/_layouts/default.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
name: Default Layout

'[testComponent]':
---
<html>
<body>

@themePage

</body>
</html>
11 changes: 0 additions & 11 deletions tests/resources/themes/tests-theme/_meta/blueprint.json

This file was deleted.

17 changes: 17 additions & 0 deletions tests/resources/themes/tests-theme/_meta/fields.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

return [
'form' => [
'general' => [
'title' => 'lang:igniter.tests::default.theme.label_title',
'fields' => [
'field1' => [
'label' => 'lang:igniter.tests::default.theme.label_field1',
'type' => 'text',
'span' => 'left',
'cssClass' => 'flex-width',
],
],
],
],
];
11 changes: 9 additions & 2 deletions tests/resources/themes/tests-theme/_pages/components.blade.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
---
title: Components
description: ''
permalink: /components
layout: default
'[testComponent]': []
---
<div class="container">
<div class="row">
@push('scripts')
Expand All @@ -16,8 +23,8 @@
<p>This is a logged customer</p>
@endmainauth

@partialIf('scriprts')
@partialIf('scripts')

@component('account')
@component('testComponent')
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
title: Layout with Lifecycle
description: ''
permalink: /layout-with-lifecycle
layout: default-with-lifecycle

'[testComponent]':
---
<div class="container">
<div class="row">
<p>This is a logged customer</p>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
title: Page with Lifecycle
description: ''
permalink: /page-with-lifecycle
layout: default

'[testComponentWithLifecycle]':
---
<div class="container">
<div class="row">
<p>This is a logged customer</p>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is a test partial content
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{ 'This is a test component partial content' }}
3 changes: 3 additions & 0 deletions tests/resources/views/_mail/test_layout.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name = 'Test Layout'
===
This is a test layout!
3 changes: 3 additions & 0 deletions tests/resources/views/_mail/test_partial.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name = 'Test Partial'
===
This is a test partial!
2 changes: 1 addition & 1 deletion tests/resources/views/_partials/test-partial.blade.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
This is a test partial view
This is a test partial content
7 changes: 7 additions & 0 deletions tests/resources/views/layout.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<html>
<body>

{{Template::getBlock('body')}}

</body>
</html>
4 changes: 1 addition & 3 deletions tests/resources/views/test.blade.php
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
<html>
<body>Hello World!</body>
</html>
This is a test view content
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php
throw new Exception('This is a test exception');
?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php
throw new Error('This is a test error');;
?>
15 changes: 15 additions & 0 deletions tests/src/Admin/BulkActionWidgets/DeleteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,18 @@

expect(StatusHistory::count())->toBe(0);
});

it('does noting when records is empty', function() {
$actionButton = new ToolbarButton('delete');
$actionButton->displayAs('link', []);

$controller = resolve(TestController::class);
$widget = new Delete($controller, $actionButton, []);
$widget->code = $actionButton->name;

expect(StatusHistory::count())->toBe(0);

$widget->handleAction([], StatusHistory::get());

expect(StatusHistory::count())->toBe(0);
});
17 changes: 17 additions & 0 deletions tests/src/Admin/BulkActionWidgets/StatusTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,20 @@

expect(StatusHistory::where($statusColumn, true)->count())->toBe(10);
});

it('does noting when records is empty', function() {
$statusColumn = 'notify';

$actionButton = new ToolbarButton('status');
$actionButton->displayAs('link', []);

$controller = resolve(TestController::class);
$widget = new Status($controller, $actionButton, ['statusColumn' => $statusColumn]);
$widget->code = $actionButton->name;

expect(StatusHistory::count())->toBe(0);

$widget->handleAction(['code' => 'action.disable'], StatusHistory::get());

expect(StatusHistory::count())->toBe(0);
});
Loading

0 comments on commit 8ee2bcf

Please sign in to comment.