Skip to content

Commit

Permalink
Ignore input metrics nodes and generate our own based on the merged d…
Browse files Browse the repository at this point in the history
…ocuments.
  • Loading branch information
d0x2f committed Oct 21, 2018
1 parent 6ca6426 commit a98d95f
Show file tree
Hide file tree
Showing 13 changed files with 9,970 additions and 322 deletions.
2 changes: 0 additions & 2 deletions clover-merge
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
<?php
require_once 'vendor/autoload.php';

error_reporting(~\E_ALL);

try {
$invocation = new \d0x2f\CloverMerge\Invocation($argv);
$invocation->execute();
Expand Down
4 changes: 0 additions & 4 deletions spec/Accumulator.spec.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use d0x2f\CloverMerge\Accumulator;
use d0x2f\CloverMerge\File;
use d0x2f\CloverMerge\Utilities;
use d0x2f\CloverMerge\Metrics;

/**
* @phan-closure-scope \Kahlan\Scope
Expand All @@ -31,9 +30,6 @@
'test.php'
]);

$metrics = $this->accumulator->getMetrics();
expect($metrics)->toBeAnInstanceOf(Metrics::class);

$file = $result->get('test.php');
expect($file)->toBeAnInstanceOf(File::class);

Expand Down
47 changes: 14 additions & 33 deletions spec/ClassT.spec.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace d0x2f\CloverMerge\Spec;

use d0x2f\CloverMerge\ClassT;
use d0x2f\CloverMerge\Metrics;

/**
* @phan-closure-scope \Kahlan\Scope
Expand All @@ -12,11 +11,11 @@
describe('__construct', function () {
context('Receives a namespace and metrics.', function () {
beforeEach(function () {
$this->metrics = new Metrics(new \Ds\Map([
$properties = new \Ds\Map([
'foo' => 'bar',
'baz' => 'fred'
]));
$this->instance = new ClassT('Example\Namespace', $this->metrics);
]);
$this->instance = new ClassT($properties);
});

it('produces a valid instance.', function () {
Expand All @@ -29,9 +28,7 @@
beforeEach(function () {
$xml_element = simplexml_load_string(
'<?xml version="1.0" encoding="UTF-8"?>
<class name="Example\Namespace\Class" namespace="Example\Namespace">
<metrics foo="bar" baz="fred" />
</class>'
<class name="Example\Namespace\Class" namespace="Example\Namespace" foo="bar" baz="fred"/>'
);
assert($xml_element !== false);
$this->instance = ClassT::fromXML($xml_element);
Expand All @@ -41,44 +38,28 @@
expect($this->instance)->toBeAnInstanceOf(ClassT::class);
});

it('has the correct namespace set.', function () {
expect($this->instance->getNamespace())->toBe('Example\Namespace');
});

it('has the correct metrics set.', function () {
expect($this->instance->getMetrics()->getProperties()->toArray())->toBe([
it('has the correct properties set.', function () {
expect($this->instance->getProperties()->toArray())->toBe([
'name' => 'Example\Namespace\Class',
'namespace' => 'Example\Namespace',
'foo' => 'bar',
'baz' => 'fred'
]);
});
});
});
describe('getNamespace', function () {
beforeEach(function () {
$this->metrics = new Metrics(new \Ds\Map([
'foo' => 'bar',
'baz' => 'fred'
]));
$this->instance = new ClassT('Example\Namespace', $this->metrics);
$this->result = $this->instance->getNamespace();
});

it('returns the properties map.', function () {
expect($this->result)->toBe('Example\Namespace');
});
});
describe('getMetrics', function () {
describe('getProperties', function () {
beforeEach(function () {
$this->metrics = new Metrics(new \Ds\Map([
$properties = new \Ds\Map([
'foo' => 'bar',
'baz' => 'fred'
]));
$this->instance = new ClassT('Example\Namespace', $this->metrics);
$this->result = $this->instance->getMetrics();
]);
$instance = new ClassT($properties);
$this->result = $instance->getProperties();
});

it('returns the properties map.', function () {
expect($this->result->getProperties()->toArray())->toBe([
expect($this->result->toArray())->toBe([
'foo' => 'bar',
'baz' => 'fred'
]);
Expand Down
57 changes: 50 additions & 7 deletions spec/File.spec.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use d0x2f\CloverMerge\File;
use d0x2f\CloverMerge\Utilities;
use d0x2f\CloverMerge\Metrics;

/**
* @phan-closure-scope \Kahlan\Scope
Expand All @@ -30,8 +31,10 @@
<metrics bar="foo" fred="baz"/>
</class>
<line num="22" type="method" name="__construct" count="1"/>
<line num="28" type="stmt" count="1"/>
<line num="29" type="stmt" count="0"/>
<line num="28" type="cond" count="1"/>
<line num="29" type="method" count="0"/>
<line num="30" type="cond" count="0"/>
<line num="31" type="method" count="1"/>
<metrics foo="bar" baz="fred"/>
</file>
');
Expand All @@ -54,19 +57,24 @@

$class = $classes->first();
expect($class->key)->toBe('Example\Namespace\Class');
expect($class->value->getNamespace())->toBe('Example\Namespace');
expect($class->value->getProperties()->toArray())->toBe([
'name' => 'Example\Namespace\Class',
'namespace' => 'Example\Namespace'
]);
});

it('has the correct lines set.', function () {
$lines = $this->instance->getLines();
expect($lines)->toHaveLength(3);
expect($lines)->toHaveLength(5);

$keys = $lines->keys();
expect($keys->toArray())->toBe([22, 28, 29]);
expect($keys->toArray())->toBe([22, 28, 29, 30, 31]);

expect($lines->get(22)->getCount())->toBe(1);
expect($lines->get(28)->getCount())->toBe(1);
expect($lines->get(29)->getCount())->toBe(0);
expect($lines->get(30)->getCount())->toBe(0);
expect($lines->get(31)->getCount())->toBe(1);
});
});
describe('Receives a XML element with errors.', function () {
Expand Down Expand Up @@ -99,6 +107,35 @@
});
});
});
describe('toXml', function () {
beforeEach(function () {
$xml_element = simplexml_load_string('
<file name="/src/Example/Namespace/Class.php">
<class name="Example\Namespace\Class" namespace="Example\Namespace">
<metrics bar="foo" fred="baz"/>
</class>
<line num="22" type="method" name="__construct" count="1"/>
<line num="25" type="method" name="foo" count="0"/>
<line num="28" type="stmt" count="1"/>
<line num="29" type="stmt" count="0"/>
<line num="30" type="cond" count="1"/>
<line num="31" type="cond" count="0"/>
<metrics foo="bar" baz="fred"/>
</file>
');
assert($xml_element !== false);
$instance = File::fromXML($xml_element, 'package_name');
$this->result = $instance->toXml(new \DOMDocument(), '/src/Example/Namespace/Class.php');
});

it('produces a DOM element.', function () {
expect($this->result[0])->toBeAnInstanceOf(\DOMElement::class);
});

it('produces a metrics object.', function () {
expect($this->result[1])->toBeAnInstanceOf(Metrics::class);
});
});
describe('merge', function () {
context('Receives a second File instance to merge into this one.', function () {
beforeEach(function () {
Expand Down Expand Up @@ -143,8 +180,14 @@
'Example\Namespace\Class'
]);

expect($classes->get('Example\Namespace\Class')->getNamespace())->toBe('Example\Namespace');
expect($classes->get('Example\Namespace\OtherClass')->getNamespace())->toBe('Example\OtherNamespace');
expect($classes->get('Example\Namespace\Class')->getProperties()->toArray())->toBe([
'name' => 'Example\Namespace\Class',
'namespace' => 'Example\Namespace'
]);
expect($classes->get('Example\Namespace\OtherClass')->getProperties()->toArray())->toBe([
'name' => 'Example\Namespace\OtherClass',
'namespace' => 'Example\OtherNamespace'
]);
});

it('has the correct lines set.', function () {
Expand Down
3 changes: 2 additions & 1 deletion spec/Invocation.spec.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use d0x2f\CloverMerge\Invocation;
use d0x2f\CloverMerge\Accumulator;
use d0x2f\CloverMerge\Utilities;
use d0x2f\CloverMerge\Metrics;

/**
* @phan-closure-scope \Kahlan\Scope
Expand Down Expand Up @@ -133,7 +134,7 @@
new \SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><coverage/>')
);
allow(Accumulator::class)->toReceive('parseAll')->andReturn();
allow(Accumulator::class)->toReceive('toXml')->andReturn(new \Ds\Map());
allow(Accumulator::class)->toReceive('toXml')->andReturn([new \Ds\Map(), new Metrics()]);
$this->invocation = new Invocation(['prog', '-o', 'test', 'path', 'path2']);
$this->closure = function () {
$this->invocation->execute();
Expand Down
Loading

0 comments on commit a98d95f

Please sign in to comment.