1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* PHP: Nelson Martell Library file |
4
|
|
|
* |
5
|
|
|
* Content: |
6
|
|
|
* - Test case for: [NelsonMartell] Object (alias for StrictObject) |
7
|
|
|
* |
8
|
|
|
* Copyright © 2016-2017 Nelson Martell (http://nelson6e65.github.io) |
9
|
|
|
* |
10
|
|
|
* Licensed under The MIT License (MIT) |
11
|
|
|
* For full copyright and license information, please see the LICENSE |
12
|
|
|
* Redistributions of files must retain the above copyright notice. |
13
|
|
|
* |
14
|
|
|
* @copyright 2016-2017 Nelson Martell |
15
|
|
|
* @link http://nelson6e65.github.io/php_nml/ |
16
|
|
|
* @since v0.6.0 |
17
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php The MIT License (MIT) |
18
|
|
|
* */ |
19
|
|
|
|
20
|
|
|
namespace NelsonMartell\Test\TestCaseLt71; |
21
|
|
|
|
22
|
|
|
use NelsonMartell as NML; |
23
|
|
|
use NelsonMartell\Extensions\Text; |
24
|
|
|
use NelsonMartell\Test\DataProviders\ObjectTestProvider; |
25
|
|
|
use NelsonMartell\Object; |
26
|
|
|
use PHPUnit\Framework\TestCase; |
27
|
|
|
use \InvalidArgumentException; |
28
|
|
|
use \Exception; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* |
32
|
|
|
* @author Nelson Martell <[email protected]> |
33
|
|
|
* @internal |
34
|
|
|
* @group Criticals |
35
|
|
|
* @requires PHP < 7.2.0 |
36
|
|
|
* |
37
|
|
|
* */ |
38
|
|
View Code Duplication |
class ObjectTest extends TestCase |
|
|
|
|
39
|
|
|
{ |
40
|
|
|
use ObjectTestProvider; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Overrides default tests, due to this class constructor do not throws argument exceptions. |
44
|
|
|
* So, using any type should be pass. |
45
|
|
|
* |
46
|
|
|
* @testdox Do not throws error on creating new instances, due to all arguments passed are ignored |
47
|
|
|
* @group Criticals |
48
|
|
|
*/ |
49
|
|
|
public function testConstructorWithBadArguments() |
50
|
|
|
{ |
51
|
|
|
$actual = null; |
|
|
|
|
52
|
|
|
$message = Text::format( |
53
|
|
|
'$object = new {class}();', |
54
|
|
|
[ |
55
|
|
|
'class' => Object::class, |
56
|
|
|
] |
57
|
|
|
); |
58
|
|
|
|
59
|
|
|
try { |
60
|
|
|
$actual = new Object(); |
61
|
|
|
} catch (Exception $e) { |
62
|
|
|
$actual = $e; |
|
|
|
|
63
|
|
|
$message .= Text::format( |
64
|
|
|
' // # Constructor should not throws exceptions. Error: {0}', |
65
|
|
|
$this->exporter->export($e->getMessage()) |
66
|
|
|
); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
$this->assertInstanceOf(Object::class, $actual, $message); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.