<?php

declare(strict_types=1);

/*
 * This file is part of the VITICORE2 package.
 *
 * (c) CP Creation <web@cpcreation.fr>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace CpCreation\VitiCore\Tests\Contact;

use CpCreation\VitiCore\Contact\ContactProvider;
use CpCreation\VitiCore\Contact\Model\Contact;
use CpCreation\VitiCore\Contact\Repository\ContactRepository;
use PHPUnit\Framework\TestCase;

final class ContactProviderTest extends TestCase
{
    public function testProvidesTheConfiguredBusinessNameAndCachesTheContact(): void
    {
        $contact = new Contact();
        $contact->setCompany('  Maison Jean-Marie Bandock  ');

        $repository = $this->createMock(ContactRepository::class);
        $repository->expects(self::once())->method('findOne')->willReturn($contact);
        $provider = new ContactProvider($repository);

        self::assertSame('Maison Jean-Marie Bandock', $provider->getBusinessName());
        self::assertSame($contact, $provider->getContact());
    }

    public function testReloadsTheContactAfterReset(): void
    {
        $repository = $this->createMock(ContactRepository::class);
        $repository->expects(self::exactly(2))->method('findOne')->willReturn(null);
        $provider = new ContactProvider($repository);

        self::assertNull($provider->getBusinessName());
        $provider->reset();
        self::assertNull($provider->getBusinessName());
    }
}
