Skip to content

Commit 7756b12

Browse files
committed
Add Pest test
1 parent 5dd38b6 commit 7756b12

File tree

9 files changed

+96
-100
lines changed

9 files changed

+96
-100
lines changed

.gitignore

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,11 @@
1-
/build
2-
/vendor
3-
/node_modules
4-
5-
.php_cs
6-
.php_cs.cache
7-
.php-cs-fixer.cache
8-
.phpunit.result.cache
1+
.idea
2+
.phpunit.cache
3+
build
94
composer.lock
10-
11-
# user specific
12-
phpunit.xml
5+
coverage
6+
docs
7+
phpunit.xml.dist
138
phpstan.neon
149
testbench.yaml
15-
16-
# ide
17-
/.idea
18-
/.vscode
19-
20-
# mac
21-
.DS_Store
10+
vendor
11+
node_modules

composer.json

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,19 @@
1717
}
1818
],
1919
"require": {
20-
"php": "^8.0",
20+
"php": "^8.1",
2121
"illuminate/contracts": "^10"
2222
},
2323
"require-dev": {
2424
"brianium/paratest": "^7",
25-
"nunomaduro/collision": "^7",
2625
"larastan/larastan": "^2.0",
26+
"laravel/pint": "^1.13",
27+
"nunomaduro/collision": "^7",
2728
"orchestra/testbench": "^8.0",
29+
"pestphp/pest": "^2.30",
2830
"phpstan/extension-installer": "^1.1",
2931
"phpstan/phpstan-deprecation-rules": "^1.0",
30-
"phpstan/phpstan-phpunit": "^1.0",
31-
"phpunit/phpunit": "^10"
32+
"phpstan/phpstan-phpunit": "^1.0"
3233
},
3334
"autoload": {
3435
"psr-4": {
@@ -41,13 +42,27 @@
4142
}
4243
},
4344
"scripts": {
44-
"phpstan": "vendor/bin/phpstan analyse",
45-
"test": "vendor/bin/phpunit",
46-
"test-coverage": "vendor/bin/phpunit --coverage-html coverage"
45+
"post-autoload-dump": "@composer run prepare",
46+
"clear": "@php vendor/bin/testbench package:purge-skeleton --ansi",
47+
"prepare": "@php vendor/bin/testbench package:discover --ansi",
48+
"build": [
49+
"@composer run prepare",
50+
"@php vendor/bin/testbench workbench:build --ansi"
51+
],
52+
"start": [
53+
"Composer\\Config::disableProcessTimeout",
54+
"@composer run build",
55+
"@php vendor/bin/testbench serve"
56+
],
57+
"analyse": "vendor/bin/phpstan analyse",
58+
"test": "vendor/bin/pest",
59+
"test-coverage": "vendor/bin/pest --coverage",
60+
"format": "vendor/bin/pint"
4761
},
4862
"config": {
4963
"sort-packages": true,
5064
"allow-plugins": {
65+
"pestphp/pest-plugin": true,
5166
"phpstan/extension-installer": true
5267
}
5368
},

phpunit.xml.dist

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,28 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit
3-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
5-
backupGlobals="false"
6-
bootstrap="vendor/autoload.php"
7-
colors="true"
8-
processIsolation="false"
9-
stopOnFailure="false"
10-
executionOrder="random"
11-
failOnWarning="true"
12-
failOnRisky="true"
13-
failOnEmptyTestSuite="true"
14-
beStrictAboutOutputDuringTests="true"
15-
cacheDirectory=".phpunit.cache"
16-
backupStaticProperties="false"
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd"
4+
backupGlobals="false"
5+
bootstrap="vendor/autoload.php"
6+
colors="true"
7+
processIsolation="false"
8+
stopOnFailure="false"
9+
executionOrder="random"
10+
failOnWarning="true"
11+
failOnRisky="true"
12+
failOnEmptyTestSuite="true"
13+
beStrictAboutOutputDuringTests="true"
14+
cacheDirectory=".phpunit.cache"
15+
backupStaticProperties="false"
1716
>
1817
<testsuites>
19-
<testsuite name="BlameButton Laravel Changelog Test Suite">
20-
<directory>tests</directory>
18+
<testsuite name="Test Suite">
19+
<directory>tests/</directory>
2120
</testsuite>
2221
</testsuites>
23-
<coverage>
24-
<report>
25-
<html outputDirectory="build/coverage"/>
26-
<text outputFile="build/coverage.txt"/>
27-
<clover outputFile="build/logs/clover.xml"/>
28-
</report>
29-
</coverage>
30-
<logging>
31-
<junit outputFile="build/report.junit.xml"/>
32-
</logging>
3322
<source>
3423
<include>
35-
<directory>src</directory>
24+
<directory>app/</directory>
25+
<directory>src/</directory>
3626
</include>
3727
</source>
3828
</phpunit>

src/Changelog.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ class Changelog
1010
{
1111
/**
1212
* Get the location of the changelog file.
13-
*
14-
* @return string
1513
*/
1614
public function path(): string
1715
{
@@ -21,7 +19,6 @@ public function path(): string
2119
/**
2220
* Get the raw content of the changelog.
2321
*
24-
* @return string
2522
* @throws ChangelogNotFoundException when the changelog file can not be found.
2623
*/
2724
public function raw(): string
@@ -37,8 +34,6 @@ public function raw(): string
3734

3835
/**
3936
* Generate a HTML version of your changelog.
40-
*
41-
* @return HtmlString
4237
*/
4338
public function html(): HtmlString
4439
{

src/ChangelogFacade.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ class ChangelogFacade extends Facade
1313
{
1414
/**
1515
* Get the registered name of the component.
16-
*
17-
* @return string
1816
*/
1917
protected static function getFacadeAccessor(): string
2018
{

src/ChangelogServiceProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function boot()
2121

2222
if ($this->app->runningInConsole()) {
2323
$this->publishes([
24-
__DIR__ . '/../config/changelog.php' => config_path('changelog.php'),
24+
__DIR__.'/../config/changelog.php' => config_path('changelog.php'),
2525
], 'config');
2626

2727
// Publishing the views.
@@ -50,7 +50,7 @@ public function boot()
5050
public function register()
5151
{
5252
// Automatically apply the package configuration
53-
$this->mergeConfigFrom(__DIR__ . '/../config/changelog.php', 'changelog');
53+
$this->mergeConfigFrom(__DIR__.'/../config/changelog.php', 'changelog');
5454

5555
// Register the main class to use with the facade
5656
$this->app->singleton('changelog', function () {

tests/ChangelogTest.php

Lines changed: 24 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,30 @@
11
<?php
22

3-
namespace BlameButton\Laravel\Changelog\Tests;
3+
declare(strict_types=1);
44

55
use BlameButton\Laravel\Changelog\Changelog;
6-
use BlameButton\Laravel\Changelog\ChangelogServiceProvider;
76
use Illuminate\Support\Facades\Storage;
87
use Mockery\MockInterface;
9-
use Orchestra\Testbench\TestCase;
10-
11-
class ChangelogTest extends TestCase
12-
{
13-
protected function getPackageProviders($app): array
14-
{
15-
return [
16-
ChangelogServiceProvider::class,
17-
];
18-
}
19-
20-
protected function setUp(): void
21-
{
22-
parent::setUp();
23-
24-
Storage::fake();
25-
}
26-
27-
public function testRaw(): void
28-
{
29-
$expected = "Changelog\n\nv1.0.0";
30-
31-
Storage::put(base_path('CHANGELOG.md'), $expected);
32-
33-
/** @var Changelog $changelog */
34-
$changelog = $this->mock(Changelog::class, function (MockInterface $mock) {
35-
$mock->shouldReceive('path')->andReturn(Storage::path(base_path('CHANGELOG.md')));
36-
$mock->shouldReceive('raw')->passthru();
37-
});
38-
39-
$content = $changelog->raw();
40-
41-
self::assertNotNull($content);
42-
self::assertEquals($expected, $content);
43-
}
44-
}
8+
9+
beforeEach(function () {
10+
Storage::fake();
11+
});
12+
13+
it('handles raw file', function () {
14+
$expected = "Changelog\n\nv1.0.0";
15+
16+
Storage::put(base_path('CHANGELOG.md'), $expected);
17+
18+
/** @var Changelog&MockInterface $changelog */
19+
$changelog = $this->mock(Changelog::class, function (Changelog&MockInterface $mock) {
20+
$mock->shouldReceive('path')->andReturn(Storage::path(base_path('CHANGELOG.md')));
21+
$mock->shouldReceive('raw')->passthru();
22+
});
23+
24+
$content = $changelog->raw();
25+
26+
expect($content)
27+
->not->toBeNull()
28+
->and($content)
29+
->toEqual($expected);
30+
});

tests/Pest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
use BlameButton\Laravel\Changelog\Tests\TestCase;
4+
5+
uses(TestCase::class)->in(__DIR__);

tests/TestCase.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace BlameButton\Laravel\Changelog\Tests;
4+
5+
6+
use BlameButton\Laravel\Changelog\ChangelogServiceProvider;
7+
use Orchestra\Testbench\TestCase as BaseTestCase;
8+
9+
abstract class TestCase extends BaseTestCase
10+
{
11+
protected function getPackageProviders($app): array
12+
{
13+
return [
14+
ChangelogServiceProvider::class,
15+
];
16+
}
17+
}

0 commit comments

Comments
 (0)