getEntitiesGeneratorService()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 6
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace Wabel\Zoho\CRM\Service;
4
5
use Psr\Log\NullLogger;
6
use Wabel\Zoho\CRM\ZohoClient;
7
8
class EntitiesGeneratorServiceTest extends \PHPUnit_Framework_TestCase
9
{
10
    public function getEntitiesGeneratorService()
0 ignored issues
show
Coding Style introduced by
getEntitiesGeneratorService uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
11
    {
12
        $client = new ZohoClient($GLOBALS['auth_token']);
13
14
        return new EntitiesGeneratorService($client, new NullLogger());
15
    }
16
17
    public function testGenerateAll()
18
    {
19
        $generator = $this->getEntitiesGeneratorService();
20
        $zohoModulesDaos = $generator->generateAll(__DIR__.'/../generated/', 'TestNamespace');
21
        $this->assertContains('TestNamespace\\LeadZohoDao', $zohoModulesDaos);
22
    }
23
24
    public function testGenerateModule()
25
    {
26
        $generator = $this->getEntitiesGeneratorService();
27
28
        $generator->generateModule('Leads', 'Leads', 'Lead', __DIR__.'/../generated/', 'TestNamespace');
29
30
        $this->assertFileExists(__DIR__.'/../generated/Lead.php');
31
32
        require __DIR__.'/../generated/Lead.php';
33
34
        // Second iteration: from existing class!
35
        $daoFullyQualified = $generator->generateModule('Leads', 'Leads', 'Lead', __DIR__.'/../generated/', 'TestNamespace');
36
37
        $this->assertFileExists(__DIR__.'/../generated/Lead.php');
38
        $this->assertEquals('TestNamespace\\LeadZohoDao', $daoFullyQualified);
39
    }
40
}
41