|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace prgTW\BaseCRM\Tests\Detached; |
|
4
|
|
|
|
|
5
|
|
|
use prgTW\BaseCRM\Resource\CustomField; |
|
6
|
|
|
use prgTW\BaseCRM\Resource\CustomFieldsCollection; |
|
7
|
|
|
use prgTW\BaseCRM\Service\Detached\Source; |
|
8
|
|
|
|
|
9
|
|
|
class SourceTest extends \PHPUnit_Framework_TestCase |
|
10
|
|
|
{ |
|
11
|
|
|
public function testCustomFields() |
|
12
|
|
|
{ |
|
13
|
|
|
$source = new Source(); |
|
14
|
|
|
$source->id = 1; |
|
|
|
|
|
|
15
|
|
|
$source->setCustomField('custom1', 'value1'); |
|
16
|
|
|
$customFields = $source->getCustomFields()->toArray(); |
|
17
|
|
|
|
|
18
|
|
|
$this->assertEquals(['custom1' => 'value1'], $customFields); |
|
19
|
|
|
$this->assertInstanceOf(CustomFieldsCollection::class, $source->getCustomFields()); |
|
20
|
|
|
$this->assertInstanceOf(CustomField::class, $source->getCustomField('custom1')); |
|
21
|
|
|
$this->assertNull($source->getCustomField('custom1')->getId()); |
|
22
|
|
|
$this->assertEquals('custom1', $source->getCustomField('custom1')->getName()); |
|
23
|
|
|
$this->assertEquals('value1', $source->getCustomField('custom1')->getValue()); |
|
24
|
|
|
$this->assertEquals(['id' => null, 'value' => 'value1'], $source->getCustomField('custom1')->getData()); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @expectedException \PHPUnit_Framework_Error_Warning |
|
29
|
|
|
*/ |
|
30
|
|
|
public function testNonExistentField() |
|
31
|
|
|
{ |
|
32
|
|
|
$source = new Source(); |
|
33
|
|
|
$source->non_existent_field; |
|
|
|
|
|
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function testMagicMethods() |
|
37
|
|
|
{ |
|
38
|
|
|
$source = new Source(); |
|
39
|
|
|
$source->id = 1; |
|
|
|
|
|
|
40
|
|
|
|
|
41
|
|
|
$this->assertEquals(1, $source->id); |
|
|
|
|
|
|
42
|
|
|
$this->assertEmpty(false, $source->id); |
|
|
|
|
|
|
43
|
|
|
$this->assertFalse(empty($source->id)); |
|
|
|
|
|
|
44
|
|
|
$this->assertTrue(isset($source->id)); |
|
45
|
|
|
} |
|
46
|
|
|
} |
|
47
|
|
|
|
Since your code implements the magic setter
_set, this function will be called for any write access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.