Skip to content

Commit

Permalink
Add Pest test
Browse files Browse the repository at this point in the history
  • Loading branch information
bram-pkg committed Jan 10, 2024
1 parent 5dd38b6 commit 7756b12
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 100 deletions.
26 changes: 8 additions & 18 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
/build
/vendor
/node_modules

.php_cs
.php_cs.cache
.php-cs-fixer.cache
.phpunit.result.cache
.idea
.phpunit.cache
build
composer.lock

# user specific
phpunit.xml
coverage
docs
phpunit.xml.dist
phpstan.neon
testbench.yaml

# ide
/.idea
/.vscode

# mac
.DS_Store
vendor
node_modules
29 changes: 22 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,19 @@
}
],
"require": {
"php": "^8.0",
"php": "^8.1",
"illuminate/contracts": "^10"
},
"require-dev": {
"brianium/paratest": "^7",
"nunomaduro/collision": "^7",
"larastan/larastan": "^2.0",
"laravel/pint": "^1.13",
"nunomaduro/collision": "^7",
"orchestra/testbench": "^8.0",
"pestphp/pest": "^2.30",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan-deprecation-rules": "^1.0",
"phpstan/phpstan-phpunit": "^1.0",
"phpunit/phpunit": "^10"
"phpstan/phpstan-phpunit": "^1.0"
},
"autoload": {
"psr-4": {
Expand All @@ -41,13 +42,27 @@
}
},
"scripts": {
"phpstan": "vendor/bin/phpstan analyse",
"test": "vendor/bin/phpunit",
"test-coverage": "vendor/bin/phpunit --coverage-html coverage"
"post-autoload-dump": "@composer run prepare",
"clear": "@php vendor/bin/testbench package:purge-skeleton --ansi",
"prepare": "@php vendor/bin/testbench package:discover --ansi",
"build": [
"@composer run prepare",
"@php vendor/bin/testbench workbench:build --ansi"
],
"start": [
"Composer\\Config::disableProcessTimeout",
"@composer run build",
"@php vendor/bin/testbench serve"
],
"analyse": "vendor/bin/phpstan analyse",
"test": "vendor/bin/pest",
"test-coverage": "vendor/bin/pest --coverage",
"format": "vendor/bin/pint"
},
"config": {
"sort-packages": true,
"allow-plugins": {
"pestphp/pest-plugin": true,
"phpstan/extension-installer": true
}
},
Expand Down
46 changes: 18 additions & 28 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,38 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
backupGlobals="false"
bootstrap="vendor/autoload.php"
colors="true"
processIsolation="false"
stopOnFailure="false"
executionOrder="random"
failOnWarning="true"
failOnRisky="true"
failOnEmptyTestSuite="true"
beStrictAboutOutputDuringTests="true"
cacheDirectory=".phpunit.cache"
backupStaticProperties="false"
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd"
backupGlobals="false"
bootstrap="vendor/autoload.php"
colors="true"
processIsolation="false"
stopOnFailure="false"
executionOrder="random"
failOnWarning="true"
failOnRisky="true"
failOnEmptyTestSuite="true"
beStrictAboutOutputDuringTests="true"
cacheDirectory=".phpunit.cache"
backupStaticProperties="false"
>
<testsuites>
<testsuite name="BlameButton Laravel Changelog Test Suite">
<directory>tests</directory>
<testsuite name="Test Suite">
<directory>tests/</directory>
</testsuite>
</testsuites>
<coverage>
<report>
<html outputDirectory="build/coverage"/>
<text outputFile="build/coverage.txt"/>
<clover outputFile="build/logs/clover.xml"/>
</report>
</coverage>
<logging>
<junit outputFile="build/report.junit.xml"/>
</logging>
<source>
<include>
<directory>src</directory>
<directory>app/</directory>
<directory>src/</directory>
</include>
</source>
</phpunit>
5 changes: 0 additions & 5 deletions src/Changelog.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ class Changelog
{
/**
* Get the location of the changelog file.
*
* @return string
*/
public function path(): string
{
Expand All @@ -21,7 +19,6 @@ public function path(): string
/**
* Get the raw content of the changelog.
*
* @return string
* @throws ChangelogNotFoundException when the changelog file can not be found.
*/
public function raw(): string
Expand All @@ -37,8 +34,6 @@ public function raw(): string

/**
* Generate a HTML version of your changelog.
*
* @return HtmlString
*/
public function html(): HtmlString
{
Expand Down
2 changes: 0 additions & 2 deletions src/ChangelogFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ class ChangelogFacade extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor(): string
{
Expand Down
4 changes: 2 additions & 2 deletions src/ChangelogServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function boot()

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

// Publishing the views.
Expand Down Expand Up @@ -50,7 +50,7 @@ public function boot()
public function register()
{
// Automatically apply the package configuration
$this->mergeConfigFrom(__DIR__ . '/../config/changelog.php', 'changelog');
$this->mergeConfigFrom(__DIR__.'/../config/changelog.php', 'changelog');

// Register the main class to use with the facade
$this->app->singleton('changelog', function () {
Expand Down
62 changes: 24 additions & 38 deletions tests/ChangelogTest.php
Original file line number Diff line number Diff line change
@@ -1,44 +1,30 @@
<?php

namespace BlameButton\Laravel\Changelog\Tests;
declare(strict_types=1);

use BlameButton\Laravel\Changelog\Changelog;
use BlameButton\Laravel\Changelog\ChangelogServiceProvider;
use Illuminate\Support\Facades\Storage;
use Mockery\MockInterface;
use Orchestra\Testbench\TestCase;

class ChangelogTest extends TestCase
{
protected function getPackageProviders($app): array
{
return [
ChangelogServiceProvider::class,
];
}

protected function setUp(): void
{
parent::setUp();

Storage::fake();
}

public function testRaw(): void
{
$expected = "Changelog\n\nv1.0.0";

Storage::put(base_path('CHANGELOG.md'), $expected);

/** @var Changelog $changelog */
$changelog = $this->mock(Changelog::class, function (MockInterface $mock) {
$mock->shouldReceive('path')->andReturn(Storage::path(base_path('CHANGELOG.md')));
$mock->shouldReceive('raw')->passthru();
});

$content = $changelog->raw();

self::assertNotNull($content);
self::assertEquals($expected, $content);
}
}

beforeEach(function () {
Storage::fake();
});

it('handles raw file', function () {
$expected = "Changelog\n\nv1.0.0";

Storage::put(base_path('CHANGELOG.md'), $expected);

/** @var Changelog&MockInterface $changelog */
$changelog = $this->mock(Changelog::class, function (Changelog&MockInterface $mock) {

Check failure on line 19 in tests/ChangelogTest.php

View workflow job for this annotation

GitHub Actions / phpstan

Undefined variable: $this
$mock->shouldReceive('path')->andReturn(Storage::path(base_path('CHANGELOG.md')));
$mock->shouldReceive('raw')->passthru();

Check failure on line 21 in tests/ChangelogTest.php

View workflow job for this annotation

GitHub Actions / phpstan

Call to an undefined method Mockery\ExpectationInterface|Mockery\HigherOrderMessage::passthru().
});

$content = $changelog->raw();

expect($content)
->not->toBeNull()
->and($content)
->toEqual($expected);
});
5 changes: 5 additions & 0 deletions tests/Pest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

use BlameButton\Laravel\Changelog\Tests\TestCase;

uses(TestCase::class)->in(__DIR__);
17 changes: 17 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace BlameButton\Laravel\Changelog\Tests;


use BlameButton\Laravel\Changelog\ChangelogServiceProvider;
use Orchestra\Testbench\TestCase as BaseTestCase;

abstract class TestCase extends BaseTestCase
{
protected function getPackageProviders($app): array
{
return [
ChangelogServiceProvider::class,
];
}
}

0 comments on commit 7756b12

Please sign in to comment.