<?php

declare(strict_types=1);

/**
 * Mockery (https://docs.mockery.io/en/stable/)
 *
 * @copyright https://github.com/mockery/mockery/blob/HEAD/COPYRIGHT.md
 * @license   https://github.com/mockery/mockery/blob/HEAD/LICENSE BSD 3-Clause License
 * @see       https://github.com/mockery/mockery for the canonical source repository
 */

namespace Tests\Unit\Mockery;

use Mockery\Adapter\Phpunit\MockeryTestCase;
use Mockery\Exception;
use Mockery\MockInterface;
use Override;
use Throwable;

use function anything;
use function greaterThan;
use function mock;

/**
 * @coversDefaultClass \Mockery
 */
final class HamcrestExpectationTest extends MockeryTestCase
{
    /**
     * @var MockInterface
     */
    protected $mock;

    #[Override]
    protected function mockeryTestSetUp(): void
    {
        $this->mock = mock('foo');
    }

    /**
     * @throws Throwable
     */
    public function testAnythingConstraintMatchesArgument(): void
    {
        $this->mock->shouldReceive('foo')
            ->with(anything())
            ->once();
        $this->mock->foo(2);
    }

    /**
     * @throws Throwable
     */
    public function testGreaterThanConstraintMatchesArgument(): void
    {
        $this->mock->shouldReceive('foo')
            ->with(greaterThan(1))
            ->once();
        $this->mock->foo(2);
    }

    /**
     * @throws Throwable
     */
    public function testGreaterThanConstraintNotMatchesArgument(): void
    {
        $this->mock->shouldReceive('foo')
            ->with(greaterThan(1));
        $this->expectException(Exception::class);
        $this->mock->foo(1);
    }
}
