Repository: symfony/symfony
File: src/Symfony/Component/DependencyInjection/Tests/Attribute/AutowireTest.php (PHP)

Code before:
        $this->expectException(LogicException::class);
        $this->expectExceptionMessage('#[Autowire] attribute must declare exactly one of $service, $expression, $env, $param or $value.');

        new Autowire($value, $service, $expression, $env, $param);
    }

    public static function provideMutuallyExclusiveOptions(): iterable
    {
        $options = ['value', 'service', 'expression', 'env', 'param'];
        $count = \count($options);
        $totalCombinations = 1 << $count;

        for ($i = 0; $i < $totalCombinations; ++$i) {
            $args = [];
            $mask = \sprintf('%0'.$count.'b', $i);

            foreach ($options as $index => $name) {
                $args[$name] = '1' === $mask[$index] ? 'some_value' : null;
            }

            if (1 === \count(array_filter($args))) {
                continue;
            }

            $activeOptions = array_keys(array_filter($args));
            $description = empty($activeOptions) ? '(none)' : implode(' + ', $activeOptions);

            yield "combination: $description" => array_values($args);
        }
    }
}


Review comment (suggestion):
we don't use empty:
```suggestion
            $description = $activeOptions ? implode(' + ', $activeOptions) : '(none)';
```

Code after:
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\DependencyInjection\Tests\Attribute;

use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\DependencyInjection\Exception\LogicException;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\ExpressionLanguage\Expression;

class AutowireTest extends TestCase
{
    /**
     * @dataProvider provideMultipleParameters
     */
    public function testCanOnlySetOneParameter(array $parameters)
    {
        $this->expectException(LogicException::class);

        new Autowire(...$parameters);
    }

    public function testMustSetOneParameter()
    {
        $this->expectException(LogicException::class);

        new Autowire();
    }

    public function testCanUseZeroForValue()
    {
        $this->assertSame('0', (new Autowire(value: '0'))->value);
    }

    public function testCanUseArrayForValue()
    {
        $this->assertSame(['FOO' => 'BAR'], (new Autowire(value: ['FOO' => 'BAR']))->value);
    }

    public function testCanUseValueWithAtSign()
    {
        $this->assertInstanceOf(Reference::class, (new Autowire(value: '@service'))->value);
    }

    public function testCanUseValueWithDoubleAtSign()
    {
        $this->assertSame('@service', (new Autowire(value: '@@service'))->value);
    }

    public function testCanUseValueWithAtAndEqualSign()
    {
        $this->assertInstanceOf(Expression::class, (new Autowire(value: '@=service'))->value);
    }

    public function testCanUseEnv()
    {
        $this->assertSame('%env(SOME_ENV_VAR)%', (new Autowire(env: 'SOME_ENV_VAR'))->value);
    }

    public function testCanUseParam()
    {
        $this->assertSame('%some.param%', (new Autowire(param: 'some.param'))->value);
    }

    /**
     * @see testCanOnlySetOneParameter
     */
    public static function provideMultipleParameters(): iterable
    {
        yield [['service' => 'id', 'expression' => 'expr']];

        yield [['env' => 'ENV', 'param' => 'param']];

        yield [['value' => 'some-value', 'expression' => 'expr']];
    }

    /**
     * @dataProvider provideMutuallyExclusiveOptions
     */
    public function testConstructThrowsOnMutuallyExclusiveOptions(array $parameters)
    {
        $this->expectException(LogicException::class);
        $this->expectExceptionMessage('#[Autowire] attribute must declare exactly one of $service, $expression, $env, $param or $value.');

        new Autowire(...$parameters);
    }

    public static function provideMutuallyExclusiveOptions(): iterable
    {
        yield [[]];
        yield [['value' => 'some-value', 'service' => 'id']];
        yield [['value' => 'some-value', 'service' => 'id', 'expression' => 'expr']];
        yield [['value' => 'some-value', 'service' => 'id', 'expression' => 'expr', 'env' => 'ENV']];
        yield [['value' => 'some-value', 'service' => 'id', 'expression' => 'expr', 'env' => 'ENV', 'param' => 'param']];
    }
}