<?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 DateTime;
use Hamcrest\Core\IsEqual;
use Mockery;
use Mockery\Adapter\Phpunit\MockeryTestCase;
use Mockery\MockInterface;
use Override;
use PHP73\CustomValueObject;
use PHP73\CustomValueObjectInterface;
use PHP73\CustomValueObjectMatcher;
use Throwable;

use function mock;

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

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

    /**
     * @throws Throwable
     */
    public function testDefaultMatcherClass(): void
    {
        Mockery::getConfiguration()->setDefaultMatcher(CustomValueObject::class, CustomValueObjectMatcher::class);
        $this->mock->shouldReceive('foo')
            ->with(new CustomValueObject('expected'))
            ->once();
        $this->mock->foo(new CustomValueObject('expected'));
    }

    /**
     * Just a quickie roundup of a few Hamcrest matchers to check nothing obvious out of place *
     *
     * @throws Throwable
     */
    public function testDefaultMatcherHamcrest(): void
    {
        Mockery::getConfiguration()->setDefaultMatcher(DateTime::class, IsEqual::class);
        $this->mock->shouldReceive('foo')
            ->with(new DateTime('2000-01-01'))
            ->once();
        $this->mock->foo(new DateTime('2000-01-01'));
    }

    /**
     * @throws Throwable
     */
    public function testDefaultMatcherInterface(): void
    {
        Mockery::getConfiguration()->setDefaultMatcher(
            CustomValueObjectInterface::class,
            CustomValueObjectMatcher::class,
        );
        $this->mock->shouldReceive('foo')
            ->with(new CustomValueObject('expected2'))
            ->once();
        $this->mock->foo(new CustomValueObject('expected2'));
    }
}
