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

[ci] windows tests on GitHub actions #1424

Merged
merged 1 commit into from
Feb 6, 2024
Merged
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
32 changes: 16 additions & 16 deletions .github/workflows/ci.yaml → .github/workflows/ci-linux.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: "CI"
name: "CI Linux"

on:
pull_request:
Expand Down Expand Up @@ -26,34 +26,34 @@ jobs:

steps:
-
name: "Checkout code"
name: Checkout code
uses: "actions/checkout@v3"

-
name: "Install PHP"
name: Install PHP
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
php-version: "${{ matrix.php-version }}"

-
name: "Validate composer.json"
name: Validate composer.json
run: "composer validate --strict --no-check-lock"

-
name: "Composer install"
name: Composer install
uses: "ramsey/composer-install@v2"
with:
composer-options: "--no-scripts"

-
name: "Composer install php-cs-fixer"
name: Composer install php-cs-fixer
uses: "ramsey/composer-install@v2"
with:
composer-options: "--no-scripts --working-dir=tools/php-cs-fixer"

-
name: "Run friendsofphp/php-cs-fixer"
name: Run PHP-CS-Fixer
run: "tools/php-cs-fixer/vendor/bin/php-cs-fixer fix --dry-run --diff"

test:
Expand Down Expand Up @@ -99,42 +99,42 @@ jobs:
dependency-versions: 'highest'

steps:
- name: "Checkout code"
- name: Checkout code
uses: actions/checkout@v3

- name: "Install PHP with extensions"
- name: Install PHP with extensions
uses: shivammathur/setup-php@v2
with:
coverage: "none"
php-version: ${{ matrix.php-version }}

- name: "Add PHPUnit matcher"
- name: Add PHPUnit matcher
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

- name: "Composer install"
- name: Composer install
uses: "ramsey/composer-install@v2"
with:
dependency-versions: "${{ matrix.dependency-versions }}"

- name: "Composer install php-cs-fixer"
- name: Composer install php-cs-fixer
uses: "ramsey/composer-install@v2"
with:
composer-options: "--no-scripts --working-dir=tools/php-cs-fixer"

- name: "Composer install twigcs"
- name: Composer install twigcs
uses: "ramsey/composer-install@v2"
with:
composer-options: "--no-scripts --working-dir=tools/twigcs"

- name: "Install PHPUnit"
- name: Install PHPUnit
run: |
if [[ ${{ matrix.dependency_versions == 'lowest' }} ]]; then
echo "SYMFONY_PHPUNIT_REQUIRE=nikic/php-parser:^4.18" >> $GITHUB_ENV
fi
vendor/bin/simple-phpunit install

- name: "PHPUnit version"
- name: PHPUnit version
run: vendor/bin/simple-phpunit --version

- name: "Run tests"
- name: Run tests
run: vendor/bin/simple-phpunit ${{ env.PHPUNIT_FLAGS }}
70 changes: 70 additions & 0 deletions .github/workflows/ci-windows.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: "CI Windows"

on:
pull_request:
push:
branches:
- 'main'
schedule:
- cron: '0 0 * * *'

env:
PHPUNIT_FLAGS: "-v"
SYMFONY_PHPUNIT_DIR: "$HOME/symfony-bridge/.phpunit"
MAKER_SKIP_MERCURE_TEST: 1
MAKER_SKIP_PANTHER_TEST: 1
MAKER_DISABLE_FILE_LINKS: 1
MAKER_ALLOW_DEV_DEPS_IN_APP: 0
SYMFONY_VERSION: '7.0.x-dev'

jobs:
tests:
name: Testing on Windows
runs-on: [windows-latest]
strategy:
fail-fast: false
matrix:
php-versions: [8.2]
dependency-versions: ['highest']
steps:
# This is needed in Windows, otherwise assertions comparing fixtures and generated code will fail.
- name: Use INPUT for autocrlf in Git Config
run: git config --global core.autocrlf input

- name: Checkout
uses: actions/checkout@v4

- name: Setup SQLite For Entity Regen Tests
run: |
choco install sqlite --params "/NoTools"

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: pdo, pdo_sqlite

- name: Composer Install
uses: "ramsey/composer-install@v2"
with:
dependency-versions: "${{ matrix.dependency-versions }}"

- name: Composer install php-cs-fixer
uses: "ramsey/composer-install@v2"
with:
composer-options: "--no-scripts --working-dir=tools/php-cs-fixer"

- name: Composer install twigcs
uses: "ramsey/composer-install@v2"
with:
composer-options: "--no-scripts --working-dir=tools/twigcs"

- name: Install PHPUnit
run: |
vendor/bin/simple-phpunit install

- name: PHPUnit Version
run: vendor/bin/simple-phpunit --version

- name: Run Tests
run: vendor/bin/simple-phpunit ${{ env.PHPUNIT_FLAGS }}
1 change: 1 addition & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<env name="SYMFONY_DEPRECATIONS_HELPER" value="max[self]=0"/>
<env name="SYMFONY_PHPUNIT_VERSION" value="9.6" />
<env name="MAKER_SKIP_MERCURE_TEST" value="false"/>
<env name="MAKER_SKIP_PANTHER_TEST" value="false" />
</php>

<testsuites>
Expand Down
6 changes: 4 additions & 2 deletions src/Test/MakerTestEnvironment.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
*/
final class MakerTestEnvironment
{
public const GENERATED_FILES_REGEX = '#(?:created|updated):\s(?:.*\\\\)*(.*\.[a-z]{3,4}).*(?:\\\\n)?#ui';

private Filesystem $fs;
private bool|string $rootPath;
private string $cachePath;
Expand Down Expand Up @@ -213,9 +215,9 @@ public function getGeneratedFilesFromOutputText(): array

$matches = [];

preg_match_all('#(created|updated): (]8;;[^]*\\\)?(.*?)(]8;;\\\)?\n#iu', $output, $matches, \PREG_PATTERN_ORDER);
preg_match_all(self::GENERATED_FILES_REGEX, $output, $matches, \PREG_PATTERN_ORDER);

return array_map('trim', $matches[3]);
return array_map('trim', $matches[1]);
}
jrushlow marked this conversation as resolved.
Show resolved Hide resolved

public function fileExists(string $file): bool
Expand Down
12 changes: 11 additions & 1 deletion tests/Maker/MakeFunctionalTestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Symfony\Bundle\MakerBundle\Maker\MakeFunctionalTest;
use Symfony\Bundle\MakerBundle\Test\MakerTestCase;
use Symfony\Bundle\MakerBundle\Test\MakerTestDetails;
use Symfony\Bundle\MakerBundle\Test\MakerTestRunner;

/**
Expand All @@ -27,7 +28,7 @@ protected function getMakerClass(): string

public function getTestDetails(): \Generator
{
yield 'it_generates_test_with_panther' => [$this->createMakerTest()
yield 'it_generates_test_with_panther' => [$this->getPantherTest()
->addExtraDependencies('panther')
->run(function (MakerTestRunner $runner) {
$runner->copy(
Expand All @@ -48,4 +49,13 @@ public function getTestDetails(): \Generator
}),
];
}

protected function getPantherTest(): MakerTestDetails
{
return $this->createMakerTest()
->skipTest(
message: 'Panther test skipped - MAKER_SKIP_PANTHER_TEST set to TRUE.',
skipped: getenv('MAKER_SKIP_PANTHER_TEST')
);
}
}
12 changes: 11 additions & 1 deletion tests/Maker/MakeTestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Symfony\Bundle\MakerBundle\Maker\MakeTest;
use Symfony\Bundle\MakerBundle\Test\MakerTestCase;
use Symfony\Bundle\MakerBundle\Test\MakerTestDetails;
use Symfony\Bundle\MakerBundle\Test\MakerTestRunner;

class MakeTestTest extends MakerTestCase
Expand Down Expand Up @@ -79,7 +80,7 @@ public function getTestDetails(): \Generator
}),
];

yield 'it_makes_PantherTestCase_type' => [$this->createMakerTest()
yield 'it_makes_PantherTestCase_type' => [$this->getPantherTest()
->addExtraDependencies('panther')
->run(function (MakerTestRunner $runner) {
$runner->copy(
Expand All @@ -103,4 +104,13 @@ public function getTestDetails(): \Generator
}),
];
}

protected function getPantherTest(): MakerTestDetails
{
return $this->createMakerTest()
->skipTest(
message: 'Panther test skipped - MAKER_SKIP_PANTHER_TEST set to TRUE.',
skipped: getenv('MAKER_SKIP_PANTHER_TEST')
);
}
}
61 changes: 61 additions & 0 deletions tests/RegexTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

/*
* This file is part of the Symfony MakerBundle package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bundle\MakerBundle\Tests;

use PHPUnit\Framework\TestCase;
use Symfony\Bundle\MakerBundle\Test\MakerTestEnvironment;

class RegexTest extends TestCase
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling this MakeTestEnvironmentTest was not compatible with PHPUnit --filter (test wouldn't run) and I'm not sure it was running w/ just simple-phpunit && no flags either...

{
/** @dataProvider regexDataProvider */
public function testRegex(string $data, array $expectedResult): void
{
$result = [];

preg_match_all(MakerTestEnvironment::GENERATED_FILES_REGEX, $data, $result, \PREG_PATTERN_ORDER);

self::assertSame($expectedResult, $result[1]);
}

public function regexDataProvider(): \Generator
{
yield 'Created Prefix' => ['created: test/something.php', ['test/something.php']];
yield 'Updated Prefix' => ['updated: test/something.php', ['test/something.php']];
yield 'Twig file' => ['created: test/something.html.twig', ['test/something.html.twig']];
yield 'Config file (no dir)' => ['updated: service.yaml', ['service.yaml']];
yield 'Line Char + 2 dir' => ['\n success\ncreated: test/somewhere/else.php\n', ['test/somewhere/else.php']];
yield 'Multiline' => [<<< 'EOT'
Congrats!\n
Created: some/file.php\n
Updated: another/config.yaml\n
\n
EOT,
['some/file.php', 'another/config.yaml'],
];
yield 'Linux CI Results' => [<<< 'EOT'
Bundled PHP-CS-Fixer & Bundled PHP-CS-Fixer Configuration\n
\n
created: \e]8;;file:///home/runner/work/maker-bundle/maker-bundle/tests/tmp/cache/maker_app_40cd750bba9870f18aada2478b24840a_6.4.x-dev/tests/FooBarTest.php#L1\e\tests/FooBarTest.php\e]8;;\e\\n
\n
EOT,
['tests/FooBarTest.php'],
];
yield 'Windows CI Results' => [<<< 'EOT'
Bundled PHP-CS-Fixer & Bundled PHP-CS-Fixer Configuration\r\n
\r\n
created: tests/FooBarTest.php\r\n
\r\n
EOT,
['tests/FooBarTest.php'],
];
}
}
Loading