IdGeneratorTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 37
c 0
b 0
f 0
rs 10
wmc 2
lcom 1
cbo 2

3 Methods

Rating   Name   Duplication   Size   Complexity  
A hp ➔ test_com_create_guid() 0 4 1
A testCreateIdFrom() 0 16 1
A testGenerate() 0 7 1
1
<?php
2
declare(strict_types=1);
3
/**
4
 * Created by PhpStorm.
5
 * User: benedikt
6
 * Date: 10/1/17
7
 * Time: 12:52 PM
8
 */
9
10
namespace Tfboe\FmLib\Tests\Unit\Entity\Helpers;
11
12
use Doctrine\ORM\EntityManager;
13
use Tfboe\FmLib\Entity\Helpers\IdGenerator;
14
use Tfboe\FmLib\Tests\Helpers\UnitTestCase;
15
16
/**
17
 * Class IdGeneratorTest
18
 * @package Tfboe\FmLib\Tests\Unit\Entity\Helpers
19
 */
20
class IdGeneratorTest extends UnitTestCase
21
{
22
//<editor-fold desc="Public Methods">
23
24
  /**
25
   * @covers \Tfboe\FmLib\Entity\Helpers\IdGenerator::createIdFrom
26
   */
27
  public function testCreateIdFrom()
28
  {
29
    /**
30
     * test function for generating an guid
31
     * @return string fixed test string
32
     */
33
    function test_com_create_guid()
34
    {
35
      return "{test-guid}";
36
    }
37
38
    self::assertEquals('test-guid',
39
      IdGenerator::createIdFrom('Tfboe\FmLib\Tests\Unit\Entity\Helpers\test_com_create_guid'));
40
41
    self::assertRegExp('/^[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}$/', IdGenerator::createIdFrom());
42
  }
43
44
  /**
45
   * @covers \Tfboe\FmLib\Entity\Helpers\IdGenerator::generate
46
   * @uses   \Tfboe\FmLib\Entity\Helpers\IdGenerator::createIdFrom
47
   */
48
  public function testGenerate()
49
  {
50
    $generator = new IdGenerator();
51
    $entityManager = $this->createMock(EntityManager::class);
52
    /** @var EntityManager $entityManager */
53
    self::assertRegExp('/^[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}$/', $generator->generate($entityManager, null));
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a object<Doctrine\ORM\Mapping\Entity>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
54
  }
55
//</editor-fold desc="Public Methods">
56
}