noregression/callable-comparator

View on GitHub
src/PHPUnit/Comparator/Callables/IsPasswordHashFor.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php

namespace NoRegression\PHPUnit\Comparator\Callables;

use \SebastianBergmann\Comparator\ComparisonFailure;

class IsPasswordHashFor extends BaseCallable
{
    private $payload;

    public function __construct($payload)
    {
        $this->payload = $payload;
    }

    public function isValid($actual)
    {
        $isValid = password_verify($this->payload, $actual);

        if ($isValid) {
            return $this->isValid = true;
        }

        throw new ComparisonFailure(
            (string)$this,
            $actual,
            '',
            '',
            false,
            sprintf('Failed asserting that \'%s\' is a password hash for \'%s\'', $actual, $this->payload)
        );
    }
}