Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
idmarinas committed Nov 28, 2024
1 parent ee2d6df commit 0bc90c9
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 0 deletions.
42 changes: 42 additions & 0 deletions tests/Traits/Entity/IdTraitTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
/**
* Copyright 2024 (C) IDMarinas - All Rights Reserved
*
* Last modified by "IDMarinas" on 28/11/24, 19:52
*
* @project IDMarinas Common Bundle
* @see https://github.com/idmarinas/common-bundle
*
* @file IdTraitTest.php
* @date 28/11/2024
* @time 19:52
*
* @author Iván Diaz Marinas (IDMarinas)
* @license BSD 3-Clause License
*
* @since 3.0.0
*/

namespace Idm\Bundle\Common\Tests\Traits\Entity;

use Idm\Bundle\Common\Traits\Entity\IdTrait;
use phpmock\phpunit\PHPMock;
use PHPUnit\Framework\TestCase;

class IdTraitTest extends TestCase
{
use PHPMock;

public function testIdTrait ()
{
$entity = new IdTraitCheck();
$entity->setId(1);

$this->assertEquals(1, $entity->getId());
}
}

class IdTraitCheck
{
use IdTrait;
}
42 changes: 42 additions & 0 deletions tests/Traits/Entity/UuidTraitTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
/**
* Copyright 2024 (C) IDMarinas - All Rights Reserved
*
* Last modified by "IDMarinas" on 28/11/24, 19:52
*
* @project IDMarinas Common Bundle
* @see https://github.com/idmarinas/common-bundle
*
* @file UuidTraitTest.php
* @date 28/11/2024
* @time 19:52
*
* @author Iván Diaz Marinas (IDMarinas)
* @license BSD 3-Clause License
*
* @since 3.0.0
*/

namespace Idm\Bundle\Common\Tests\Traits\Entity;

use Idm\Bundle\Common\Traits\Entity\UuidTrait;
use PHPUnit\Framework\TestCase;
use Ramsey\Uuid\UuidFactory;

class UuidTraitTest extends TestCase
{
public function testUuid ()
{
$entity = new UuidTraitCheck();

$uuid = (new UuidFactory())->uuid4();
$entity->setUuid($uuid);

$this->assertEquals($uuid, $entity->getUuid());
}
}

class UuidTraitCheck
{
use UuidTrait;
}
47 changes: 47 additions & 0 deletions tests/Traits/Tool/FakerTraitTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
/**
* Copyright 2024 (C) IDMarinas - All Rights Reserved
*
* Last modified by "IDMarinas" on 28/11/24, 19:33
*
* @project IDMarinas Common Bundle
* @see https://github.com/idmarinas/common-bundle
*
* @file FakerTraitTest.php
* @date 28/11/2024
* @time 19:33
*
* @author Iván Diaz Marinas (IDMarinas)
* @license BSD 3-Clause License
*
* @since 3.0.0
*/

namespace Idm\Bundle\Common\Tests\Traits\Tool;

use Idm\Bundle\Common\Traits\Tool\FakerTrait;
use LogicException;
use phpmock\phpunit\PHPMock;
use PHPUnit\Framework\TestCase;
use ReflectionClass;

class FakerTraitTest extends TestCase
{
use PHPMock;

public function testFakerNotInstalled ()
{
$this->expectException(LogicException::class);

$namespace = (new ReflectionClass(FakerTrait::class))->getNamespaceName();
$mock = $this->getFunctionMock($namespace, 'class_exists');
$mock->expects($this->once())->willReturn(false);

(new FakerCheck())->faker();
}
}

class FakerCheck
{
use FakerTrait;
}

0 comments on commit 0bc90c9

Please sign in to comment.