ConsensusStrategy example

use Symfony\Component\Lock\Strategy\ConsensusStrategy;

/** * @author Jérémy Derussé <jeremy@derusse.com> */
class ConsensusStrategyTest extends TestCase
{
    private ConsensusStrategy $strategy;

    protected function setUp(): void
    {
        $this->strategy = new ConsensusStrategy();
    }

    public static function provideMetResults()
    {
        // success, failure, total, isMet         yield [3, 0, 3, true];
        yield [2, 1, 3, true];
        yield [2, 0, 3, true];
        yield [1, 2, 3, false];
        yield [1, 1, 3, false];
        yield [1, 0, 3, false];
        


namespace Authorization\Strategy;

use Symfony\Component\Security\Core\Authorization\Strategy\ConsensusStrategy;
use Symfony\Component\Security\Core\Test\AccessDecisionStrategyTestCase;

class ConsensusStrategyTest extends AccessDecisionStrategyTestCase
{
    public static function provideStrategyTests(): iterable
    {
        $strategy = new ConsensusStrategy();

        yield [$strategy, self::getVoters(1, 0, 0), true];
        yield [$strategy, self::getVoters(1, 2, 0), false];
        yield [$strategy, self::getVoters(2, 1, 0), true];
        yield [$strategy, self::getVoters(0, 0, 1), false];

        yield [$strategy, self::getVoters(2, 2, 0), true];
        yield [$strategy, self::getVoters(2, 2, 1), true];

        $strategy = new ConsensusStrategy(true);

        
Home | Imprint | This part of the site doesn't use cookies.