|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * This file is part of the PHPFUI\ConstantContact package |
| 5 | + * |
| 6 | + * (c) Bruce Wells |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view |
| 9 | + * the LICENSE.md file that was distributed with this source |
| 10 | + * code |
| 11 | + */ |
| 12 | +class DefinitionTest extends \PHPUnit\Framework\TestCase |
| 13 | + { |
| 14 | + |
| 15 | + public function testGetSet() : void |
| 16 | + { |
| 17 | + $fixture = new \Tests\Fixtures\TypeTest(); |
| 18 | + $integer = 123; |
| 19 | + $fixture->integer = $integer; |
| 20 | + $this->assertEquals($integer, $fixture->integer); |
| 21 | + $this->assertIsInt($fixture->integer); |
| 22 | + |
| 23 | + $string = 'A long string'; |
| 24 | + $fixture->string = $string; |
| 25 | + $this->assertEquals($string, $fixture->string); |
| 26 | + $this->assertIsString($fixture->string); |
| 27 | + |
| 28 | + $boolean = true; |
| 29 | + $fixture->boolean = $boolean; |
| 30 | + $this->assertEquals($boolean, $fixture->boolean); |
| 31 | + $this->assertIsBool($fixture->boolean); |
| 32 | + |
| 33 | + $array = [1, 2, 3]; |
| 34 | + $fixture->array = $array; |
| 35 | + $this->assertEquals($array, $fixture->array); |
| 36 | + $this->assertIsArray($fixture->array); |
| 37 | + |
| 38 | + $float = 1.23; |
| 39 | + $fixture->float = $float; |
| 40 | + $this->assertEquals($float, $fixture->float); |
| 41 | + $this->assertIsFloat($fixture->float); |
| 42 | + |
| 43 | + $string = 'primary_email'; |
| 44 | + $fixture->enum = $string; |
| 45 | + $this->assertEquals($string, $fixture->enum); |
| 46 | + $this->assertIsString($fixture->enum); |
| 47 | + |
| 48 | + $integer = 1; |
| 49 | + $fixture->intEnum = $integer; |
| 50 | + $this->assertEquals($integer, $fixture->intEnum); |
| 51 | + $this->assertIsInt($fixture->intEnum); |
| 52 | + |
| 53 | + $string = 'REMOVED'; |
| 54 | + $fixture->ucEnum = $string; |
| 55 | + $this->assertEquals($string, $fixture->ucEnum); |
| 56 | + $this->assertIsString($fixture->ucEnum); |
| 57 | + |
| 58 | + $class = new \Tests\Fixtures\ClassTest(); |
| 59 | + $fixture->class = $class; |
| 60 | + $this->assertEquals($class, $fixture->class); |
| 61 | + $this->assertIsObject($fixture->class); |
| 62 | + |
| 63 | + $json = $fixture->getJSON(); |
| 64 | + $expectedJSON ='{ |
| 65 | + "class": {}, |
| 66 | + "integer": 123, |
| 67 | + "string": "A long string", |
| 68 | + "boolean": true, |
| 69 | + "array": [ |
| 70 | + 1, |
| 71 | + 2, |
| 72 | + 3 |
| 73 | + ], |
| 74 | + "float": 1.23, |
| 75 | + "enum": "primary_email", |
| 76 | + "intEnum": 1, |
| 77 | + "ucEnum": "REMOVED" |
| 78 | +}'; |
| 79 | + // normalize line endings |
| 80 | + $expectedJSON = str_replace("\r\n", "\n", $expectedJSON); |
| 81 | + $this->assertEquals($expectedJSON, $json); |
| 82 | + } |
| 83 | + |
| 84 | + public function testBadField() : void |
| 85 | + { |
| 86 | + $fixture = new \Tests\Fixtures\TypeTest(); |
| 87 | + $this->expectException(\PHPFUI\ConstantContact\Exception\InvalidField::class); |
| 88 | + $fixture->badField = 'test'; |
| 89 | + } |
| 90 | + |
| 91 | + public function testBadIntType() : void |
| 92 | + { |
| 93 | + $fixture = new \Tests\Fixtures\TypeTest(); |
| 94 | + $this->expectException(\PHPFUI\ConstantContact\Exception\InvalidType::class); |
| 95 | + $fixture->integer = 'test'; |
| 96 | + } |
| 97 | + |
| 98 | + public function testBadStringType() : void |
| 99 | + { |
| 100 | + $fixture = new \Tests\Fixtures\TypeTest(); |
| 101 | + $this->expectException(\PHPFUI\ConstantContact\Exception\InvalidType::class); |
| 102 | + $fixture->string = 123; |
| 103 | + } |
| 104 | + |
| 105 | + public function testBadFloatType() : void |
| 106 | + { |
| 107 | + $fixture = new \Tests\Fixtures\TypeTest(); |
| 108 | + $this->expectException(\PHPFUI\ConstantContact\Exception\InvalidType::class); |
| 109 | + $fixture->float = 'abc'; |
| 110 | + } |
| 111 | + |
| 112 | + public function testBadBooleanType() : void |
| 113 | + { |
| 114 | + $fixture = new \Tests\Fixtures\TypeTest(); |
| 115 | + $this->expectException(\PHPFUI\ConstantContact\Exception\InvalidType::class); |
| 116 | + $fixture->boolean = 0; |
| 117 | + } |
| 118 | + |
| 119 | + public function testBadArrayType() : void |
| 120 | + { |
| 121 | + $fixture = new \Tests\Fixtures\TypeTest(); |
| 122 | + $this->expectException(\PHPFUI\ConstantContact\Exception\InvalidType::class); |
| 123 | + $fixture->array = 0; |
| 124 | + } |
| 125 | + |
| 126 | + public function testBadClassType() : void |
| 127 | + { |
| 128 | + $fixture = new \Tests\Fixtures\TypeTest(); |
| 129 | + $this->expectException(\PHPFUI\ConstantContact\Exception\InvalidType::class); |
| 130 | + $fixture->class = new \DateTime(); |
| 131 | + } |
| 132 | + |
| 133 | + public function testBadEnum() : void |
| 134 | + { |
| 135 | + $fixture = new \Tests\Fixtures\TypeTest(); |
| 136 | + $this->expectException(\PHPFUI\ConstantContact\Exception\InvalidValue::class); |
| 137 | + $fixture->enum = 'fred'; |
| 138 | + } |
| 139 | + |
| 140 | + public function testMinLength() : void |
| 141 | + { |
| 142 | + $fixture = new \Tests\Fixtures\TypeTest(); |
| 143 | + $this->expectException(\PHPFUI\ConstantContact\Exception\InvalidLength::class); |
| 144 | + $fixture->string = 'fred'; |
| 145 | + } |
| 146 | + |
| 147 | + public function testMaxLength() : void |
| 148 | + { |
| 149 | + $fixture = new \Tests\Fixtures\TypeTest(); |
| 150 | + $this->expectException(\PHPFUI\ConstantContact\Exception\InvalidLength::class); |
| 151 | + $fixture->string = str_pad('', 100); |
| 152 | + } |
| 153 | + |
| 154 | + public function testGeneratedClass() : void |
| 155 | + { |
| 156 | + $fixture = new \PHPFUI\ConstantContact\Definition\EmailCampaignActivity(); |
| 157 | + $this->expectException(\PHPFUI\ConstantContact\Exception\InvalidType::class); |
| 158 | + $fixture->physical_address_in_footer = new \DateTime(); |
| 159 | + } |
| 160 | + |
| 161 | + } |
0 commit comments