Completed
Pull Request — master (#1)
by Davis
01:51
created

TestPost::testConstructor()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 8

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: davis
5
 * Date: 7/23/17
6
 * Time: 7:25 PM
7
 */
8
9
namespace DavisPeixoto\BlogCore\Tests\Entity;
10
11
use DateTime;
12
use DavisPeixoto\BlogCore\Entity\Post;
13
use DavisPeixoto\BlogCore\Entity\Author;
14
use DavisPeixoto\BlogCore\Entity\Tag;
15
use PHPUnit_Framework_TestCase;
16
use Ramsey\Uuid\Uuid;
17
18
class TestPost extends PHPUnit_Framework_TestCase
19
{
20
    /**
21
     * @param $uuid
22
     * @param $title
23
     * @param $body
24
     * @param $author
25
     * @param $tags
26
     * @param $publishDate
27
     * @param $expected
28
     * @param $message
29
     * @dataProvider postConstructor
30
     */
31
    public function testConstructor($uuid, $title, $body, $author, $tags, $publishDate, $expected, $message)
32
    {
33
        $post = new Post($uuid, $title, $body, $author, $tags, $publishDate);
34
        $this->assertInstanceOf($expected, $post, $message);
35
    }
36
37
    public function postConstructor()
38
    {
39
        return [
40
            [Uuid::uuid4(), 'A Post', 'Lorem ipsum', new Author(Uuid::uuid4(), 'Davis', '[email protected]', 'Some string', new DateTime()), [], null, Post::class, 'no tags, no publish date'],
41
            [Uuid::uuid4(), 'A Post', 'Lorem ipsum', new Author(Uuid::uuid4(), 'Davis', '[email protected]', 'Some string', new DateTime()), [new Tag(Uuid::uuid4(),'tag1'), new Tag(Uuid::uuid4(),'tag2')], null, Post::class, 'have tags, unpublished'],
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 200 characters; contains 250 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
42
            [Uuid::uuid4(), 'A Post', 'Lorem ipsum', new Author(Uuid::uuid4(), 'Davis', '[email protected]', 'Some string', new DateTime()), [], new DateTime(), Post::class, 'no tags, published'],
43
            [Uuid::uuid4(), 'A Post', 'Lorem ipsum', new Author(Uuid::uuid4(), 'Davis', '[email protected]', 'Some string', new DateTime()), [new Tag(Uuid::uuid4(),'tag1'), new Tag(Uuid::uuid4(),'tag2')], new DateTime(), Post::class, 'tags, published (most common scenario)']
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 200 characters; contains 275 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
44
        ];
45
    }
46
}
47