<?php

namespace App\Tests\Twig;

use App\Entity\Contrats;
use App\Entity\Devis;
use App\Service\Signature\Client as SignatureClient;
use App\Service\Stripe\Client as StripeClientService;
use App\Twig\StripeExtension;
use Doctrine\ORM\EntityManagerInterface;
use PHPUnit\Framework\TestCase;
use Vich\UploaderBundle\Storage\StorageInterface;
use Vich\UploaderBundle\Templating\Helper\UploaderHelper;

class StripeExtensionTest extends TestCase
{
    public function testGetFiltersAndFunctions(): void
    {
        $storage = $this->createStub(StorageInterface::class);
        $uploaderHelper = new UploaderHelper($storage);
        
        $signatureClient = $this->createStub(SignatureClient::class);
        $stripeClient = $this->createStub(StripeClientService::class);
        $em = $this->createStub(EntityManagerInterface::class);

        $extension = new StripeExtension($uploaderHelper, $signatureClient, $stripeClient, $em);

        $this->assertIsArray($extension->getFilters());
        $this->assertIsArray($extension->getFunctions());
    }

    public function testTotalQuoto(): void
    {
        $storage = $this->createStub(StorageInterface::class);
        $uploaderHelper = new UploaderHelper($storage);
        $signatureClient = $this->createStub(SignatureClient::class);
        $stripeClient = $this->createStub(StripeClientService::class);
        $em = $this->createStub(EntityManagerInterface::class);

        $extension = new StripeExtension($uploaderHelper, $signatureClient, $stripeClient, $em);

        $devis = $this->createStub(Devis::class);
        $devis->method('getDevisLines')->willReturn(new \Doctrine\Common\Collections\ArrayCollection([]));
        $devis->method('getDevisOptions')->willReturn(new \Doctrine\Common\Collections\ArrayCollection([]));

        $total = $extension->totalQuoto($devis);
        $this->assertIsFloat($total);
    }
    
    public function testTotalContrat(): void
    {
        $storage = $this->createStub(StorageInterface::class);
        $uploaderHelper = new UploaderHelper($storage);
        $signatureClient = $this->createStub(SignatureClient::class);
        $stripeClient = $this->createStub(StripeClientService::class);
        $em = $this->createStub(EntityManagerInterface::class);

        $extension = new StripeExtension($uploaderHelper, $signatureClient, $stripeClient, $em);

        $contrat = $this->createStub(Contrats::class);
        $contrat->method('getContratsLines')->willReturn(new \Doctrine\Common\Collections\ArrayCollection([]));
        $contrat->method('getContratsOptions')->willReturn(new \Doctrine\Common\Collections\ArrayCollection([]));
        $contrat->method('getDateAt')->willReturn(new \DateTimeImmutable());
        $contrat->method('getEndAt')->willReturn(new \DateTimeImmutable());

        $total = $extension->totalContrat($contrat);
        $this->assertIsFloat($total);
    }
}
