Skip to content

Commit 9785529

Browse files
author
Mitchell Macpherson
authored
Laravel functional tests (#3)
* Test runner * Change path detection Added in PHPT test for asserting a real world laravel application behaves as expected with this package L5.8 for lols Actually use different laravel versions ignore platform reqs L6 and above only Remove big swears * Maybe fix test * change branch name * remove --no-suggests from composer. Fix branch for new workflow * Maybe fix tests
1 parent c8a48fd commit 9785529

9 files changed

+152
-7
lines changed

.github/workflows/code-coverage.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ on:
2121
jobs:
2222
code-cov:
2323
runs-on: ubuntu-latest
24-
name: Code coverage peport
24+
name: Code coverage report
2525
steps:
2626
- name: Checkout code
2727
uses: actions/checkout@v2
@@ -36,7 +36,7 @@ jobs:
3636

3737
- name: Install dependencies
3838
run: |
39-
composer install --no-plugins --no-scripts --no-suggest --no-interaction --no-progress --prefer-dist
39+
composer install --no-plugins --no-scripts --no-interaction --no-progress --prefer-dist
4040
4141
- name: Execute tests
4242
run: vendor/bin/phpunit --coverage-clover coverage.xml

.github/workflows/laravel-test.yaml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: Laravel IRL tests
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
laravel-tests:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
php: [ 7.2, 7.3, 7.4 ]
16+
#laravel: [~5.6.0, ~5.7.0, ~5.8.0, ~5.9.0, ^6.0, ^7.0, ^8.0]
17+
laravel: [ ^6.0, ^7.0, ^8.0 ]
18+
exclude:
19+
- php: 7.2
20+
laravel: ^8.0
21+
22+
name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }}
23+
24+
steps:
25+
- name: Checkout code
26+
uses: actions/checkout@v2
27+
with:
28+
path: 'console-logg-package'
29+
30+
- name: Setup PHP
31+
uses: shivammathur/setup-php@v2
32+
with:
33+
php-version: ${{ matrix.php }}
34+
extensions: dom, curl, libxml, mbstring, zip
35+
tools: composer:v2
36+
coverage: none
37+
38+
- name: Install console-logg dependencies
39+
run: |
40+
cd console-logg-package
41+
composer install --no-plugins --no-scripts --no-interaction --no-progress --prefer-dist
42+
43+
- name: Setup Laravel application
44+
run: |
45+
composer create-project --prefer-dist laravel/laravel:${{ matrix.laravel }} laravel-app
46+
cd laravel-app
47+
48+
- name: Add local path composer dependency
49+
run: |
50+
cd laravel-app
51+
jq '.repositories[0].type="path"' composer.json > composer.temp.json
52+
jq '.repositories[0].url="../console-logg-package"' composer.json > composer.temp.json
53+
jq '.require."devthis/console-logg"="*"' composer.json > composer.temp.json
54+
mv composer.temp.json composer.json
55+
composer update --no-interaction --no-progress --ignore-platform-reqs
56+
57+
- name: Copy fixtures into Laravel app
58+
run: |
59+
mkdir -p laravel-app/app/Console/Commands
60+
cp console-logg-package/tests/Fixtures/ArtisanCommand.php laravel-app/app/Console/Commands/
61+
cp console-logg-package/tests/Fixtures/ServiceThatLoggs.php laravel-app/app/
62+
63+
- name: Run Laravel package discovery
64+
run: |
65+
cd laravel-app
66+
php artisan package:discover --ansi
67+
php artisan clear-compiled
68+
69+
- name: Run PHPT
70+
run: |
71+
cd console-logg-package
72+
vendor/bin/phpunit tests/PhpTestCase/ --testdox

.github/workflows/tests.yaml renamed to .github/workflows/phpunit-tests.yaml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ on:
1919
- 'composer.*'
2020

2121
jobs:
22-
tests:
22+
phpunit-tests:
2323
runs-on: ubuntu-latest
2424
strategy:
2525
fail-fast: false
@@ -47,13 +47,11 @@ jobs:
4747

4848
- name: Install dependencies
4949
run: |
50-
composer require "illuminate/contracts=${{ matrix.laravel }}" --no-plugins --no-scripts --no-suggest --no-interaction --no-progress --prefer-dist
51-
composer update --no-plugins --no-scripts --no-suggest --no-interaction --no-progress --prefer-dist
50+
composer require "illuminate/contracts=${{ matrix.laravel }}" --no-plugins --no-scripts --no-interaction --no-progress --prefer-dist
51+
composer update --no-plugins --no-scripts --no-interaction --no-progress --prefer-dist
5252
5353
- name: Configure matchers
5454
uses: mheap/phpunit-matcher-action@v1
5555

5656
- name: Execute tests
5757
run: vendor/bin/phpunit --teamcity
58-
env:
59-
STRIPE_SECRET: ${{ secrets.STRIPE_SECRET }}

CHANGELOG.md

Whitespace-only changes.

phpunit.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
<testsuite name="unit">
1111
<directory>tests/Unit</directory>
1212
</testsuite>
13+
<testsuite name="phpt">
14+
<directory>tests/PhpTestCase</directory>
15+
<directory suffix=".phpt">test</directory>
16+
</testsuite>
1317
</testsuites>
1418

1519
<filter>

tests/Fixtures/ArtisanCommand.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Console\Commands;
6+
7+
use App\ServiceThatLoggs;
8+
use Illuminate\Console\Command;
9+
10+
class ArtisanCommand extends Command
11+
{
12+
/**
13+
* The console command description.
14+
*/
15+
protected $description = '';
16+
17+
/**
18+
* The name and signature of the console command.
19+
*/
20+
protected $signature = 'console-logg:test';
21+
22+
public function handle(ServiceThatLoggs $service): int
23+
{
24+
return 0;
25+
}
26+
}

tests/Fixtures/ServiceThatLoggs.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App;
6+
7+
use Psr\Log\LoggerInterface;
8+
9+
class ServiceThatLoggs
10+
{
11+
public function __construct(LoggerInterface $logger)
12+
{
13+
$logger->emergency('nice');
14+
$logger->info('and');
15+
$logger->alert('cool');
16+
}
17+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--TEST--
2+
artisan command log output without verbosity
3+
--FILE--
4+
<?php declare(strict_types=1);
5+
$_SERVER['argv'][0] = 'artisan';
6+
$_SERVER['argv'][1] = 'console-logg:test';
7+
8+
require __DIR__ . '/../../../laravel-app/artisan';
9+
10+
--EXPECT--
11+
#!/usr/bin/env php
12+
[emergency] nice
13+
[alert] cool

tests/Unit/Providers/ConsoleLoggServiceProviderTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,19 @@ public function testRegisterDoesNothingForNonConsole(): void
7777
$app->get(FilterableConsoleLoggerFactoryInterface::class)
7878
);
7979
}
80+
81+
public function testRegisterSetsFakeLoggingChannel(): void
82+
{
83+
$app = new ApplicationFake();
84+
$serviceProvider = new ConsoleLoggServiceProvider($app);
85+
$expectationBefore = null;
86+
$expectationAfter = ['logging.channels.console-logg' => ['driver' => 'console-logg']];
87+
$actualBefore = $app['config'] ?? null;
88+
$serviceProvider->register();
89+
90+
$result = $app['config'] ?? null;
91+
92+
self::assertSame($expectationAfter, $result);
93+
self::assertSame($expectationBefore, $actualBefore);
94+
}
8095
}

0 commit comments

Comments
 (0)