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