Completed
Push — master ( 4bb011...4b99be )
by Guillaume
13:23
created

CampaignManagerTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 0
loc 67
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 1
A testFindAll() 0 10 1
A testInsertNewCampaign() 0 15 1
A testUpdateCampaign() 0 16 1
1
<?php
2
3
namespace Starkerxp\CampaignBundle\Tests\Manager;
4
5
use Starkerxp\CampaignBundle\Entity\Campaign;
6
use Starkerxp\CampaignBundle\Manager\CampaignManager;
7
8
class CampaignManagerTest extends \Starkerxp\StructureBundle\Tests\WebTest
9
{
10
    /** @var CampaignManager */
11
    protected $manager;
12
13
    public function setUp()
14
    {
15
        parent::setUp();
16
        $this->manager = $this->getContainer()->get('starkerxp_campaign.manager.campaign');
17
    }
18
19
    /**
20
     * @group campaign
21
     * @group manager
22
     */
23
    public function testFindAll()
24
    {
25
        $this->loadFixtureFiles(
26
            [
27
                '@StarkerxpUserBundle/Tests/DataFixtures/UserManager/DefaultUser.yml',
28
                '@StarkerxpCampaignBundle/Tests/DataFixtures/CampaignManager/CampaignManager.yml',
29
            ]
30
        );
31
        $this->assertCount(10, $this->manager->findAll());
32
    }
33
34
    /**
35
     * @group campaign
36
     * @group manager
37
     */
38
    public function testInsertNewCampaign()
39
    {
40
        $this->loadFixtureFiles(
41
            [
42
                '@StarkerxpUserBundle/Tests/DataFixtures/UserManager/DefaultUser.yml',
43
                '@StarkerxpCampaignBundle/Tests/DataFixtures/CampaignManager/DefaultCampaign.yml',
44
            ]
45
        );
46
        $campaign = new \Starkerxp\CampaignBundle\Entity\Campaign();
47
        $campaign->setName('Ma super campaign');
48
        $campaign->setDeleted(false);
49
        $campaign->setStatus(Campaign::DRAFT);
50
        $this->manager->insert($campaign);
51
        $this->assertCount(2, $this->manager->findAll());
52
    }
53
54
    /**
55
     * @group campaign
56
     * @group manager
57
     */
58
    public function testUpdateCampaign()
59
    {
60
        $this->loadFixtureFiles(
61
            [
62
                '@StarkerxpUserBundle/Tests/DataFixtures/UserManager/DefaultUser.yml',
63
                '@StarkerxpCampaignBundle/Tests/DataFixtures/CampaignManager/DefaultCampaign.yml',
64
            ]
65
        );
66
        $criteria = ['createdAt' => new \DateTime('2016-08-05 12:12:12')];
67
        $campaign = $this->manager->findOneBy($criteria);
68
        $campaign->setStatus(Campaign::ERROR);
69
        $this->manager->update($campaign);
0 ignored issues
show
Documentation introduced by
$campaign is of type object|null, but the function expects a object<Starkerxp\StructureBundle\Entity\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...
70
        $campaignPostUpdate = $this->manager->findOneBy($criteria);
71
        $this->assertEquals(Campaign::ERROR, $campaignPostUpdate->getStatus());
72
        $this->assertNotEmpty($campaignPostUpdate->getUpdatedAt());
73
    }
74
}
0 ignored issues
show
Coding Style introduced by
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
75