Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@
"symfony/process": "^5.4|^6.3"
},
"require-dev": {
"matthiasnoback/symfony-config-test": "^5.0",
"symfony/filesystem": "^6.3",
"symfony/framework-bundle": "^6.3",
"symfony/phpunit-bridge": "^6.3",
"phpstan/phpstan": "1.11.x-dev"
"phpstan/phpstan-symfony": "^1.4"
},
"minimum-stability": "dev",
"autoload": {
Expand Down
11 changes: 4 additions & 7 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
includes:
- vendor/phpstan/phpstan-symfony/extension.neon
Copy link
Member

Choose a reason for hiding this comment

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

Though probably if we want to link this directly from the vendor - it may require the phpstan/phpstan-symfony pack, but probably only that one, phpstan/phpstan is redundant I think.

Btw, I suppose this line fixed that ignored error message you deleted below, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes it did :)


parameters:
level: 4
level: 5
paths:
- src

ignoreErrors:
-
message: "#^Call to an undefined method Symfony\\\\Component\\\\Config\\\\Definition\\\\Builder\\\\NodeParentInterface\\:\\:defaultValue\\(\\)\\.$#"
count: 1
path: src/DependencyInjection/SymfonycastsSassExtension.php
16 changes: 16 additions & 0 deletions src/DependencyInjection/SymfonycastsSassExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,22 @@ public function getConfigTreeBuilder(): TreeBuilder
->cannotBeEmpty()
->scalarPrototype()
->end()
->validate()
->ifTrue(static function (array $paths): bool {
if (1 === \count($paths)) {
return false;
}

$filenames = [];
foreach ($paths as $path) {
$filename = basename($path, '.scss');
$filenames[$filename] = $filename;
}

return \count($filenames) !== \count($paths);
})
->thenInvalid('The root sass-paths need to end with unique filenames.')
->end()
->defaultValue(['%kernel.project_dir%/assets/styles/app.scss'])
->end()
->scalarNode('binary')
Expand Down
62 changes: 62 additions & 0 deletions tests/ConfigurationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

declare(strict_types=1);

/*
* This file is part of the SymfonyCasts SassBundle package.
* Copyright (c) SymfonyCasts <https://symfonycasts.com/>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfonycasts\SassBundle\Tests;

use Matthias\SymfonyConfigTest\PhpUnit\ConfigurationTestCaseTrait;
use PHPUnit\Framework\TestCase;
use Symfonycasts\SassBundle\DependencyInjection\SymfonycastsSassExtension;

final class ConfigurationTest extends TestCase
{
use ConfigurationTestCaseTrait;

protected function getConfiguration(): SymfonycastsSassExtension
{
return new SymfonycastsSassExtension();
}

public function testSingleSassRootPath(): void
{
$this->assertConfigurationIsValid([
'symfonycasts_sass' => [
'root_sass' => [
'%kernel.project_dir%/assets/scss/app.scss',
],
],
]);
}

public function testMultipleSassRootPaths(): void
{
$this->assertConfigurationIsValid([
'symfonycasts_sass' => [
'root_sass' => [
'%kernel.project_dir%/assets/scss/app.scss',
'%kernel.project_dir%/assets/admin/scss/admin.scss',
],
],
]);
}

public function testMultipleSassRootPathsWithSameFilename(): void
{
$this->assertConfigurationIsInvalid([
'symfonycasts_sass' => [
'root_sass' => [
'%kernel.project_dir%/assets/scss/app.scss',
'%kernel.project_dir%/assets/admin/scss/app.scss',
],
],
],
'Invalid configuration for path "symfonycasts_sass.root_sass": The root sass-paths need to end with unique filenames.');
}
}