UsofacTest   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 9
c 2
b 0
f 0
lcom 1
cbo 3
dl 0
loc 56
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 16 1
A testCheckTotalEntities() 0 6 1
B testValidateEntity() 0 19 7
1
<?php
2
3
namespace ADiaz\AML\OpenList\parsers;
4
5
use ADiaz\AML\OpenList\models\Entity;
6
use ADiaz\AML\OpenList\utils\Exporter;
7
8
/**
9
 * This file is part of the OpenList Parser utility.
10
 *
11
 *
12
 * @category  PHP
13
 *
14
 * @author    Alberto Diaz <[email protected]>
15
 * @copyright 2016 Alberto Diaz <[email protected]>
16
 * @license   This source file is subject to the MIT license that is bundled
17
 *
18
 * @version   Release: @package_version@
19
 *
20
 * @link      http://tytem.com
21
 */
22
class UsofacTest extends \PHPUnit_Framework_TestCase
23
{
24
    protected $parser;
25
    protected $output_file;
26
    protected $output_folder;
27
28
    protected function setUp()
29
    {
30
        // output file and folder
31
        $this->output_folder = __DIR__.'/../../../output/';
32
        $this->output_file = $this->output_folder.'test_ofac_'.date('Y-m-d').'.json';
33
34
        // parser
35
        $this->parser = new Usofac();
36
        //@Todo use the helper to create the fixtures and use it
37
        $this->parser->setSourcePath(__DIR__.'/../fixtures/lists/usofac_2016-03-25.xml');
38
        $this->parser->run();
39
40
        // export
41
        $exporter = new Exporter($this->output_folder);
42
        $exporter->json($this->parser->getEntities(), 'test_ofac');
43
    }
44
45
    /**
46
     * Test run.
47
     */
48
    public function testCheckTotalEntities()
49
    {
50
        $entitiesOk = json_decode(file_get_contents($this->output_file), true);
51
52
        $this->assertEquals(count($this->parser->getEntities()), count($entitiesOk), 'The number of sanctions should be the same');
53
    }
54
55
    /*
56
     * Validate an entity
57
     */
58
    public function testValidateEntity()
59
    {
60
        $entitiesOk = json_decode(file_get_contents($this->output_file), true);
61
62
        $found = false;
63
64
        foreach ($entitiesOk as $entity) {
65
            if ($entity['external_id'] == '36'
66
                && $entity['last_name'] === 'AEROCARIBBEAN AIRLINES'
67
                && $entity['type'] === 'Entity'
68
                && $entity['program_list'][0]['program'] === 'CUBA'
69
                && $entity['aka_list'][0]['last_name'] === 'AERO-CARIBBEAN'
70
              ) {
71
                $found = true;
72
                break;
73
            }
74
        }
75
        $this->assertTrue($found, 'An entity was not found');
76
    }
77
}
78