Skip to content

Commit

Permalink
🚨 Improve Scrutinizer code quality score, and add code coverage badge.
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieutu committed Jan 11, 2018
1 parent be65d8f commit 84a232c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 21 deletions.
11 changes: 6 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# Exporter: Export the attributes you need from all your objects and arrays.

<a href="https://travis-ci.org/mathieutu/exporter"><img src="https://img.shields.io/travis/mathieutu/exporter/master.svg" alt="Build Status"></img></a>
<a href="https://scrutinizer-ci.com/g/mathieutu/exporter"><img src="https://img.shields.io/scrutinizer/g/mathieutu/exporter.svg" alt="Quality Score"></img></a>
<a href="https://packagist.org/packages/mathieutu/exporter"><img src="https://poser.pugx.org/mathieutu/exporter/d/total.svg" alt="Total Downloads"></a>
<a href="https://packagist.org/packages/mathieutu/exporter"><img src="https://poser.pugx.org/mathieutu/exporter/v/stable.svg" alt="Latest Stable Version"></a>
<a href="https://packagist.org/packages/mathieutu/exporter"><img src="https://poser.pugx.org/mathieutu/exporter/license.svg" alt="License"></a>
<a href="https://travis-ci.org/mathieutu/exporter"><img src="https://img.shields.io/travis/mathieutu/exporter/master.svg?style=flat-square" alt="Build Status"></img></a>
<a href="https://scrutinizer-ci.com/g/mathieutu/exporter"><img src="https://img.shields.io/scrutinizer/g/mathieutu/exporter.svg?style=flat-square" alt="Quality Score"></img></a>
<a href="https://scrutinizer-ci.com/g/mathieutu/exporter"><img src="https://img.shields.io/scrutinizer/coverage/g/mathieutu/exporter.svg?style=flat-square" alt="Code Coverage"></img></a>
<a href="https://packagist.org/packages/mathieutu/exporter"><img src="https://poser.pugx.org/mathieutu/exporter/d/total.svg?format=flat-square" alt="Total Downloads"></a>
<a href="https://packagist.org/packages/mathieutu/exporter"><img src="https://poser.pugx.org/mathieutu/exporter/v/stable.svg?format=flat-square" alt="Latest Stable Version"></a>
<a href="https://packagist.org/packages/mathieutu/exporter"><img src="https://poser.pugx.org/mathieutu/exporter/license.svg?format=flat-square" alt="License"></a>

## Installation

Expand Down
44 changes: 28 additions & 16 deletions tests/ExporterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,30 @@ class ExporterTest extends TestCase
{
public function testExport()
{
$exportable = new Model([
$this->assertSame(
$this->expectedExport(),
$this->exportable()->export($this->attributesToExport())->toArray()
);
}

protected function expectedExport(): array
{
return [
'test' => 'testTUDISCO',
'bar' => ['bar2' => 'testBar2'],
'bar.bar1' => 'testBar1',
'foobar' => 'testFooBar2',
'baz' => [
['baz1' => 'baz1A', 'baz3' => 'baz3A'],
['baz1' => 'baz1B', 'baz3' => 'baz3B'],
['baz1' => 'baz1C', 'baz3' => 'baz3C'],
],
];
}

protected function exportable(): Model
{
return new Model([
'foo' => 'testFoo',
'bar' => ['bar1' => 'testBar1', 'bar2' => 'testBar2'],
'foobar' => ['foobar1' => 'testFooBar1', 'foobar2' => 'testFooBar2'],
Expand All @@ -19,28 +42,17 @@ public function testExport()
['baz1' => 'baz1C', 'baz2' => 'baz2C', 'baz3' => 'baz3C'],
],
]);
}

$attributes = [
protected function attributesToExport(): array
{
return [
'test(Mathieu)',
'test(TUDISCO)',
'bar' => ['bar2'],
'bar.bar1',
'foobar' => 'foobar2',
'baz' => ['*' => ['baz1', 'baz3']],
];

$expectedExport = [
'test' => 'testTUDISCO',
'bar' => ['bar2' => 'testBar2'],
'bar.bar1' => 'testBar1',
'foobar' => 'testFooBar2',
'baz' => [
['baz1' => 'baz1A', 'baz3' => 'baz3A'],
['baz1' => 'baz1B', 'baz3' => 'baz3B'],
['baz1' => 'baz1C', 'baz3' => 'baz3C'],
],
];

$this->assertEquals($expectedExport, $exportable->export($attributes)->toArray());
}
}

0 comments on commit 84a232c

Please sign in to comment.