1: <?php
2:
3: /**
4: * Copyright 2015, Eduardo Trujillo
5: *
6: * For the full copyright and license information, please view the LICENSE
7: * file that was distributed with this source code.
8: *
9: * This file is part of the Nucleus package
10: */
11:
12: namespace Chromabits\Nucleus\Testing\Traits;
13:
14: use Exception;
15:
16: /**
17: * Trait ConstructorTesterTrait.
18: *
19: * @property array constructorTypes
20: *
21: * @author Eduardo Trujillo <ed@chromabits.com>
22: * @package Chromabits\Nucleus\Testing\Traits
23: */
24: trait ConstructorTesterTrait
25: {
26: /**
27: * @return mixed
28: */
29: abstract protected function make();
30:
31: /**
32: * Test the constructor of an object.
33: *
34: * Creates a new instance by using make and optionally checks
35: * if it is an instance of a set of classes and interfaces
36: */
37: public function testConstructor()
38: {
39: $instance = $this->make();
40:
41: $this->assertInternalType('object', $instance);
42:
43: if (property_exists($this, 'constructorTypes')
44: && count($this->constructorTypes) > 0
45: ) {
46: $this->assertInstanceOf($this->constructorTypes, $instance);
47: }
48: }
49:
50: /**
51: * Assert that the provided object is an instance of a class.
52: *
53: * @param string $expected
54: * @param string $actual
55: * @param string $message
56: *
57: * @return mixed
58: */
59: abstract public function assertInstanceOf(
60: $expected,
61: $actual,
62: $message = ''
63: );
64:
65: /**
66: * Assert the provided input of a certain internal (scalar) type.
67: *
68: * @param string $expected
69: * @param string $actual
70: * @param string $message
71: *
72: * @return mixed
73: */
74: abstract public function assertInternalType(
75: $expected,
76: $actual,
77: $message = ''
78: );
79: }
80: