GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#75)
by joseph
14:44
created

MoneyEmbeddableTest::setup()

Size

Total Lines 27
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 27
c 0
b 0
f 0
nc 1
nop 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A MoneyEmbeddableTest.php$0 ➔ __construct() 0 3 1
1
<?php declare(strict_types=1);
2
3
namespace EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Objects\Financial;
4
5
use Doctrine\ORM\Mapping\ClassMetadata;
6
use EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Interfaces\Objects\Financial\MoneyEmbeddableInterface;
7
use EdmondsCommerce\DoctrineStaticMeta\Entity\Interfaces\ImplementNotifyChangeTrackingPolicyInterface;
8
use EdmondsCommerce\DoctrineStaticMeta\Entity\Traits\ImplementNotifyChangeTrackingPolicy;
9
use Money\Currency;
10
use Money\Money;
11
use PHPUnit\Framework\TestCase;
12
13
/**
14
 * Class MoneyEmbeddableTest
15
 *
16
 * @package EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Objects\Financial
17
 * @coversDefaultClass \EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Objects\Financial\MoneyEmbeddable
18
 * @SuppressWarnings(PHPMD.UnusedLocalVariable)
19
 */
20
class MoneyEmbeddableTest extends TestCase
21
{
22
    /**
23
     * @var MoneyEmbeddable
24
     */
25
    private $embeddable;
26
27
    public function setup()
28
    {
29
        $entity           = new class() implements ImplementNotifyChangeTrackingPolicyInterface
30
        {
31
            private static $metaData;
32
33
            /**
34
             *  constructor.
35
             *
36
             */
37
            public function __construct()
38
            {
39
                self::$metaData = new ClassMetadata('anon');
40
            }
41
42
            use ImplementNotifyChangeTrackingPolicy;
43
        };
44
        $this->embeddable = new MoneyEmbeddable();
45
        $this->embeddable->setOwningEntity($entity);
46
        //using reflection as would happen with Doctrine hydrating an object
47
        $reflection = new \ReflectionObject($this->embeddable);
48
        $propAmount = $reflection->getProperty(MoneyEmbeddableInterface::EMBEDDED_PROP_AMOUNT);
49
        $propAmount->setAccessible(true);
50
        $propAmount->setValue($this->embeddable, 100);
51
        $propCurrencyCode = $reflection->getProperty(MoneyEmbeddableInterface::EMBEDDED_PROP_CURRENCY_CODE);
52
        $propCurrencyCode->setAccessible(true);
53
        $propCurrencyCode->setValue($this->embeddable, 'GBP');
54
    }
55
56
    /**
57
     * @test
58
     * @small
59
     * @covers ::getMoney()
60
     */
61
    public function itCanGetTheMoneyObject(): void
62
    {
63
        $actual = $this->embeddable->getMoney();
64
        self::assertNotFalse($actual);
65
    }
66
67
    /**
68
     * @test
69
     * @small
70
     * @covers ::setMoney()
71
     */
72
    public function itCanSetANewMoneyObject(): void
73
    {
74
        $newMoney = new Money(200, new Currency('GBP'));
75
        $this->embeddable->setMoney($newMoney);
76
        $expected = $newMoney;
77
        $actual   = $this->embeddable->getMoney();
78
        self::assertSame($expected, $actual);
79
    }
80
81
    /**
82
     * @test
83
     * @small
84
     * @covers ::addMoney()
85
     */
86
    public function itCanAddToTheMoney(): void
87
    {
88
        $toAdd = new Money(100, new Currency('GBP'));
89
        $this->embeddable->addMoney($toAdd);
90
        $expected = '200';
91
        $actual   = $this->embeddable->getMoney()->getAmount();
92
        self::assertSame($expected, $actual);
93
    }
94
95
    /**
96
     * @test
97
     * @small
98
     * @covers ::subtractMoney()
99
     */
100
    public function itCanSubtractFromTheMoney(): void
101
    {
102
        $toSubtract = new Money(60, new Currency('GBP'));
103
        $this->embeddable->subtractMoney($toSubtract);
104
        $expected = '40';
105
        $actual   = $this->embeddable->getMoney()->getAmount();
106
        self::assertSame($expected, $actual);
107
    }
108
}
109