|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Author: Nil Portugués Calderó <[email protected]> |
|
4
|
|
|
* Date: 12/18/15 |
|
5
|
|
|
* Time: 10:46 PM. |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace NilPortugues\SchemaOrg\Generator; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Class SchemaTestClassWriter. |
|
15
|
|
|
*/ |
|
16
|
|
|
class SchemaTestClassWriter extends SchemaWriter |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @param SchemaRdfaData $schemaData |
|
20
|
|
|
*/ |
|
21
|
|
|
public function write(SchemaRdfaData $schemaData) |
|
22
|
|
|
{ |
|
23
|
|
|
foreach ($schemaData->getClassesWithPropertyNames() as $class) { |
|
24
|
|
|
$className = $class->name; |
|
25
|
|
|
$methods = []; |
|
26
|
|
|
|
|
27
|
|
|
if (!empty($class->properties)) { |
|
28
|
|
|
foreach ($class->properties as $property) { |
|
29
|
|
|
$propertyName = $property['name']; |
|
30
|
|
|
$propertyNameMethodName = $propertyName; |
|
31
|
|
|
$propertyNameMethodName[0] = strtoupper($propertyNameMethodName[0]); |
|
32
|
|
|
|
|
33
|
|
|
if (empty($usableProperties[$propertyNameMethodName])) { |
|
34
|
|
|
$methods[$propertyName] = <<<PHP |
|
35
|
|
|
public function test{$propertyNameMethodName}WillReturnMappingObject() |
|
36
|
|
|
{ |
|
37
|
|
|
\$this->assertInstanceOf(Mapping::class, {$className}::{$propertyName}()); |
|
38
|
|
|
} |
|
39
|
|
|
PHP; |
|
40
|
|
|
} |
|
41
|
|
|
} |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
ksort($methods, SORT_REGULAR); |
|
45
|
|
|
$methods = implode("\n\n", $methods); |
|
46
|
|
|
|
|
47
|
|
|
$schemaData = (array) $class; |
|
48
|
|
|
|
|
49
|
|
|
$phpCode = <<<PHP |
|
50
|
|
|
<?php |
|
51
|
|
|
/** |
|
52
|
|
|
* Author: Nil Portugués Calderó <[email protected]> |
|
53
|
|
|
* Date: 12/18/15 |
|
54
|
|
|
* Time: 11:36 PM. |
|
55
|
|
|
* |
|
56
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
57
|
|
|
* file that was distributed with this source code. |
|
58
|
|
|
*/ |
|
59
|
|
|
|
|
60
|
|
|
namespace NilPortugues\Tests\SchemaOrg\Classes; |
|
61
|
|
|
|
|
62
|
|
|
use NilPortugues\\SchemaOrg\\Classes\\{$schemaData['name']}; |
|
63
|
|
|
use NilPortugues\\SchemaOrg\\Mapping; |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Classes {$schemaData['name']}Test |
|
67
|
|
|
* @package NilPortugues\\Tests\\SchemaOrg\\Classes |
|
68
|
|
|
*/ |
|
69
|
|
|
class {$schemaData['name']}Test extends \PHPUnit_Framework_TestCase |
|
70
|
|
|
{ |
|
71
|
|
|
public function testSchemaUrlReturnsExpectedUrl() |
|
72
|
|
|
{ |
|
73
|
|
|
\$this->assertEquals({$schemaData['name']}::schemaUrl(), "{$schemaData['url']}"); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
$methods |
|
77
|
|
|
} |
|
78
|
|
|
PHP; |
|
79
|
|
|
|
|
80
|
|
|
$this->fileSystem->write($this->savePath.DIRECTORY_SEPARATOR.$className.'Test.php', $phpCode); |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|