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

drop support for php <8.1 #122

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
18 changes: 17 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php: [7.2, 7.3, 7.4, 8.0, 8.1]
php: [8.1, 8.2]
steps:
- uses: actions/checkout@v1
- uses: shivammathur/setup-php@v2
Expand All @@ -19,4 +19,20 @@ jobs:
run: composer install --prefer-dist --no-progress
- name: Run tests
run: php vendor/bin/phpspec run
phpunit:
runs-on: ubuntu-latest
strategy:
matrix:
php: [8.1, 8.2]
steps:
- uses: actions/checkout@v1
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
- name: Validate Composer files
run: composer validate --no-check-all --strict
- name: Install Composer dependencies
run: composer install --prefer-dist --no-progress
- name: Run tests
run: php vendor/bin/phpunit

3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.phpunit.result.cache
studio.json
composer.phar
composer.lock
vendor/
vendor/
21 changes: 14 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,23 @@
"Studio\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"StudioTests\\": "tests"
}
},
"require": {
"php": ">=7.0",
"composer-plugin-api": "^1.0 || ^2.0",
"symfony/console": "^2.7 || ^3.0 || ^4.0 || ^5.0 || ^6.0",
"symfony/filesystem": "^2.5 || ^3.0 || ^4.0 || ^5.0 || ^6.0",
"symfony/process": "^2.5 || ^3.0 || ^4.0 || ^5.0 || ^6.0"
"php": ">=8.1",
"composer-plugin-api": "^2.3",
"symfony/console": "^6.2",
"symfony/filesystem": "^6.2",
"symfony/process": "^6.2"
},
"require-dev": {
"composer/composer": "^2.4.2",
"phpspec/phpspec": "^6.3 || ^7.0"
"composer/composer": "^2.5",
"phpspec/phpspec": "^7.4",
"phpunit/phpunit": "^9.6 | ^10",
"mikey179/vfsstream": "^1.6.11"
},
"replace": {
"franzliedke/studio": "self.version"
Expand Down
17 changes: 17 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit bootstrap = "vendor/autoload.php" colors = "true">

<testsuites>
<testsuite name="Project Test Suite">
<directory>tests</directory>
<exclude>tests/**/stubs</exclude>
</testsuite>
</testsuites>

<php>
<env name="APP_ENV" value="testing"/>
<env name="APP_VERSION" value="0.15.0"/>
</php>

</phpunit>
2 changes: 1 addition & 1 deletion src/Creator/SkeletonCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function create()

protected function installParts()
{
$config = new \stdClass();
$config = (object)[];

foreach ($this->parts as $part) {
$part->setupPackage($config, $this->directory);
Expand Down
2 changes: 1 addition & 1 deletion src/Parts/Composer/Part.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function setupPackage($composer, Directory $target)
// Normalize and store the namespace
$namespace = str_replace('/', '\\', $namespace);
$namespace = rtrim($namespace, '\\');
@$composer->autoload->{'psr-4'}->{"$namespace\\"} = 'src/';
$composer->autoload = (object)['psr-4' => (object)["$namespace\\" => 'src/']];

// Create an example file
$this->copyTo(
Expand Down
2 changes: 1 addition & 1 deletion src/Parts/PhpSpec/Part.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Part extends AbstractPart
public function setupPackage($composer, Directory $target)
{
if ($this->input->confirm('Do you want to set up PhpSpec as a testing tool?')) {
$composer->{'require-dev'}['phpspec/phpspec'] = '^4.0';
$composer->{'require-dev'}['phpspec/phpspec'] = '^7.4';

$psr4Autoloading = (array) $composer->autoload->{'psr-4'};
$namespace = key($psr4Autoloading).'Tests';
Expand Down
4 changes: 2 additions & 2 deletions src/Parts/PhpUnit/Part.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ class Part extends AbstractPart
public function setupPackage($composer, Directory $target)
{
if ($this->input->confirm('Do you want to set up PhpUnit as a testing tool?')) {
$composer->{'require-dev'}['phpunit/phpunit'] = '^6.3';
$composer->{'require-dev'}['phpunit/phpunit'] = '^9.6 || ^10';

// Add autoloading rules for tests
$psr4Autoloading = (array) $composer->autoload->{'psr-4'};
$namespace = key($psr4Autoloading).'Tests';

@$composer->{'autoload-dev'}->{'psr-4'}->{"$namespace\\"} = 'tests/';
$composer->{'autoload-dev'} = (object)['psr-4' => (object)["$namespace\\" => 'tests/']];

// Create an example test file
$this->copyTo(
Expand Down
30 changes: 30 additions & 0 deletions tests/Console/AbstractConsoleTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace StudioTests\Console;

use PHPUnit\Framework\TestCase;
use Studio\Console\CreateCommand;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Tester\CommandTester;

abstract class AbstractConsoleTest extends TestCase
{
protected function executeCommand(array $arguments, array $inputs = []): CommandTester
{
$application = new Application('studio', getenv('APP_VERSION'));
$application->add(new CreateCommand);

// this uses a special testing container that allows you to fetch private services
/** @var Command $command */
$command = $application->get($this->getCommandFqcn());

$commandTester = new CommandTester($command);
$commandTester->setInputs($inputs);
$commandTester->execute($arguments);

return $commandTester;
}

abstract protected function getCommandFqcn(): string;
}
69 changes: 69 additions & 0 deletions tests/Console/CreateTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

namespace StudioTests\Console;

use org\bovigo\vfs\vfsStream;
use org\bovigo\vfs\visitor\vfsStreamStructureVisitor;

class CreateTest extends AbstractConsoleTest
{
private $root;

public function setUp(): void
{
$this->root = vfsStream::setup();
}

function testExecute(): void
{
$commandTester = $this->executeCommand(
['path' => $this->root->url() . '/company/my-package'],
[
// package name
'company/my-package',
// default namespace (psr-4)
'Company/MyPackage',
// set up PhpUnit
'yes',
// set up PhpSpec
'yes',
// set up TravisCI
'yes'
]
);

$this->assertEquals(
self::getStructure(),
vfsStream::inspect(new vfsStreamStructureVisitor())->getStructure()
);
}

protected function getCommandFqcn(): string
{
return 'create';
}

protected static function getStructure(): array
{
return [
'root' => [
'company' => [
'my-package' => [
'spec' => [],
'src' => [
'Example.php' => file_get_contents(__DIR__ . '/stubs/company/my-package/src/Example.php'),
],
'tests' => [
'ExampleTest.php' => file_get_contents(__DIR__ . '/stubs/company/my-package/tests/ExampleTest.php'),
],
'.gitignore' => file_get_contents(__DIR__ . '/stubs/company/my-package/.gitignore'),
'.travis.yml' => file_get_contents(__DIR__ . '/stubs/company/my-package/.travis.yml'),
'composer.json' => file_get_contents(__DIR__ . '/stubs/company/my-package/composer.json'),
'phpspec.yml' => file_get_contents(__DIR__ . '/stubs/company/my-package/phpspec.yml'),
'phpunit.xml' => file_get_contents(__DIR__ . '/stubs/company/my-package/phpunit.xml'),
],
],
],
];
}
}
3 changes: 3 additions & 0 deletions tests/Console/stubs/company/my-package/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
composer.phar
composer.lock
vendor
13 changes: 13 additions & 0 deletions tests/Console/stubs/company/my-package/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
language: php

php:
- 5.5
- 5.6
- 7.0
- hhvm

before_script:
- travis_retry composer self-update
- travis_retry composer install --prefer-source --no-interaction --dev

script: phpunit
17 changes: 17 additions & 0 deletions tests/Console/stubs/company/my-package/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "company/my-package",
"autoload": {
"psr-4": {
"Company\\MyPackage\\": "src/"
}
},
"require-dev": {
"phpunit/phpunit": "^9.6 || ^10",
"phpspec/phpspec": "^7.4"
},
"autoload-dev": {
"psr-4": {
"Company\\MyPackage\\Tests\\": "tests/"
}
}
}
4 changes: 4 additions & 0 deletions tests/Console/stubs/company/my-package/phpspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
suites:
library_suite:
namespace: Company\MyPackage\Tests
psr4_prefix: Company\MyPackage\Tests
19 changes: 19 additions & 0 deletions tests/Console/stubs/company/my-package/phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
verbose="true"
>
<testsuites>
<testsuite name="Package Test Suite">
<directory suffix=".php">./tests/</directory>
</testsuite>
</testsuites>
</phpunit>
8 changes: 8 additions & 0 deletions tests/Console/stubs/company/my-package/src/Example.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Company\MyPackage;

class Example
{

}
10 changes: 10 additions & 0 deletions tests/Console/stubs/company/my-package/tests/ExampleTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Company\MyPackage\Tests;

use PHPUnit\Framework\TestCase;

class ExampleTest extends TestCase
{

}