Skip to content

Commit 0373429

Browse files
committed
fixed definition, refactoring parent test
1 parent a780815 commit 0373429

File tree

6 files changed

+136
-67
lines changed

6 files changed

+136
-67
lines changed

tests/src/Helper/LevelOneClass.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Yaoi\Schema\Tests\Helper;
4+
5+
6+
use Yaoi\Schema\ObjectFlavour\Properties;
7+
use Yaoi\Schema\Schema;
8+
use Yaoi\Schema\Structure\ClassStructure;
9+
10+
class LevelOneClass extends ClassStructure
11+
{
12+
/**
13+
* @var LevelTwoClass
14+
*/
15+
public $level1;
16+
17+
/**
18+
* @param Properties|static $properties
19+
* @param Schema $ownerSchema
20+
*/
21+
public static function setUpProperties($properties, Schema $ownerSchema)
22+
{
23+
$properties->level1 = LevelTwoClass::makeSchema();
24+
}
25+
26+
27+
}

tests/src/Helper/LevelThreeClass.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace Yaoi\Schema\Tests\Helper;
4+
5+
6+
use Yaoi\Schema\ObjectFlavour\Properties;
7+
use Yaoi\Schema\Schema;
8+
use Yaoi\Schema\Structure\ClassStructure;
9+
use Yaoi\Schema\Types\IntegerType;
10+
11+
class LevelThreeClass extends ClassStructure
12+
{
13+
/**
14+
* @var int
15+
*/
16+
public $level3;
17+
18+
/**
19+
* @param Properties|static $properties
20+
* @param Schema $ownerSchema
21+
*/
22+
public static function setUpProperties($properties, Schema $ownerSchema)
23+
{
24+
$properties->level3 = IntegerType::makeSchema();
25+
}
26+
27+
28+
}

tests/src/Helper/LevelTwoClass.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Yaoi\Schema\Tests\Helper;
4+
5+
6+
use Yaoi\Schema\ObjectFlavour\Properties;
7+
use Yaoi\Schema\Schema;
8+
use Yaoi\Schema\Structure\ClassStructure;
9+
10+
class LevelTwoClass extends ClassStructure
11+
{
12+
/**
13+
* @var LevelThreeClass
14+
*/
15+
public $level2;
16+
17+
/**
18+
* @param Properties|static $properties
19+
* @param Schema $ownerSchema
20+
*/
21+
public static function setUpProperties($properties, Schema $ownerSchema)
22+
{
23+
$properties->level2 = LevelThreeClass::makeSchema();
24+
}
25+
26+
27+
}

tests/src/Schema/ParentFixedTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace Yaoi\Schema\Tests\Schema;
4+
5+
6+
use Yaoi\Schema\Tests\Helper\LevelOneClass;
7+
8+
class ParentFixedTest extends ParentTest
9+
{
10+
protected function deepSchema()
11+
{
12+
$schema = LevelOneClass::makeSchema();
13+
return $schema;
14+
}
15+
16+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace Yaoi\Schema\Tests\Schema;
4+
5+
6+
use Yaoi\Schema\ObjectFlavour\Properties;
7+
use Yaoi\Schema\Types\IntegerType;
8+
use Yaoi\Schema\Types\ObjectType;
9+
10+
class ParentSymbolicTest extends ParentTest
11+
{
12+
protected function deepSchema()
13+
{
14+
$schema = ObjectType::makeSchema(
15+
Properties::create()
16+
->setProperty(
17+
'level1',
18+
ObjectType::makeSchema(
19+
Properties::create()
20+
->setProperty(
21+
'level2',
22+
ObjectType::makeSchema(
23+
Properties::create()
24+
->setProperty(
25+
'level3',
26+
IntegerType::makeSchema()
27+
)
28+
)
29+
)
30+
)
31+
)
32+
);
33+
return $schema;
34+
}
35+
36+
}

tests/src/Schema/ParentTest.php

Lines changed: 2 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@
66
use Yaoi\Schema\Exception;
77
use Yaoi\Schema\ObjectFlavour\Properties;
88
use Yaoi\Schema\Schema;
9-
use Yaoi\Schema\Types\IntegerType;
10-
use Yaoi\Schema\Types\ObjectType;
119

1210
class ParentTest extends \PHPUnit_Framework_TestCase
1311
{
14-
private function deepSchema()
12+
protected function deepSchema()
1513
{
1614
$schemaValue = array(
1715
'type' => 'object',
@@ -36,29 +34,7 @@ private function deepSchema()
3634
}
3735

3836

39-
private function deepSchemaSymbolic()
40-
{
41-
$schema = ObjectType::makeSchema(
42-
Properties::create()
43-
->setProperty(
44-
'level1',
45-
ObjectType::makeSchema(
46-
Properties::create()
47-
->setProperty(
48-
'level2',
49-
ObjectType::makeSchema(
50-
Properties::create()
51-
->setProperty(
52-
'level3',
53-
IntegerType::makeSchema()
54-
)
55-
)
56-
)
57-
)
58-
)
59-
);
60-
return $schema;
61-
}
37+
6238

6339
private function assertSchema(Schema $schema)
6440
{
@@ -78,13 +54,6 @@ private function assertSchema(Schema $schema)
7854
public function testParent()
7955
{
8056
$this->assertSchema($this->deepSchema());
81-
$this->assertSchema($this->deepSchemaSymbolic());
82-
}
83-
84-
85-
public function testAttach()
86-
{
87-
8857
}
8958

9059

@@ -109,27 +78,6 @@ public function testInvalidImport()
10978
//$this->assertSame('abc', $object->level1->level2->level3);
11079
}
11180

112-
public function testInvalidImportSymbolic()
113-
{
114-
$schema = $this->deepSchemaSymbolic();
115-
$this->setExpectedException(get_class(new Exception()), 'Validation failed (level1->level2->level3)',
116-
Exception::INVALID_VALUE);
117-
try {
118-
$object = $schema->import(array(
119-
'level1' => array(
120-
'level2' => array(
121-
'level3' => 'abc' // integer required
122-
),
123-
),
124-
));
125-
} catch (Exception $exception) {
126-
$this->assertSame(array('level1', 'level2', 'level3'), $exception->getStructureTrace());
127-
throw $exception;
128-
}
129-
//$this->assertSame('abc', $object->level1->level2->level3);
130-
}
131-
132-
13381
public function testImport()
13482
{
13583
$object = $this->deepSchema()->import(array(
@@ -141,17 +89,4 @@ public function testImport()
14189
));
14290
$this->assertSame(123, $object->level1->level2->level3);
14391
}
144-
145-
public function testImportSymbolic()
146-
{
147-
$object = $this->deepSchemaSymbolic()->import(array(
148-
'level1' => array(
149-
'level2' => array(
150-
'level3' => 123 // integer required
151-
),
152-
),
153-
));
154-
$this->assertSame(123, $object->level1->level2->level3);
155-
}
156-
15792
}

0 commit comments

Comments
 (0)