/
TestCase.php
148 lines (121 loc) · 4.68 KB
/
TestCase.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?php
namespace integration\UCD;
use UCD\Console\Application\Container\ApplicationServiceProvider;
use UCD\Console\Application\Container\RepositoryServiceProvider;
use UCD\Unicode\Character;
use UCD\Unicode\Character\Properties\General\Block;
use UCD\Unicode\Character\Properties\General\GeneralCategory;
use UCD\Unicode\Character\Properties\General\Script;
use UCD\Unicode\Codepoint;
use UCD\Unicode\Character\Properties;
use UCD\Console\Application\Container;
use Hamcrest\MatcherAssert as ha;
use VirtualFileSystem\FileSystem;
abstract class TestCase extends \PHPUnit_Framework_TestCase
{
/**
* @var FileSystem
*/
protected $fs;
/**
* @var Container
*/
protected $container;
/**
* @param string|null $name
* @param array $data
* @param string $dataName
*/
public function __construct($name = null, array $data = [], $dataName = '')
{
$this->fs = new FileSystem();
$this->container = new Container();
parent::__construct($name, $data, $dataName);
}
/**
* The providers are not loaded by default.
*/
protected function registerContainerProviders()
{
$this->container->register(new ApplicationServiceProvider());
$this->container->register(new RepositoryServiceProvider());
}
/**
* Adds Hamcrest assertion counts to PHPUnit
*/
public function runBare()
{
$e = null;
ha::resetCount();
try {
parent::runBare();
} catch (\Exception $e) { }
$this->addToAssertionCount(ha::getCount());
if ($e !== null) {
throw $e;
}
}
/**
* @param Codepoint $cp
* @param Block $block
* @param GeneralCategory $cat
* @param Script $script
* @return Character
*/
protected function buildCharacterWithCodepoint(
Codepoint $cp,
Block $block = null,
GeneralCategory $cat = null,
Script $script = null
) {
$general = $this->buildGeneralProperties($block, $cat, $script);
$letterCase = $this->buildLetterCase($cp);
$numericity = $this->buildNumericity();
$normalization = $this->buildNormalization();
$bidi = $this->buildBidirectionality();
$shaping = $this->buildShaping();
$properties = new Character\Properties($general, $letterCase, $numericity, $normalization, $bidi, $shaping);
return new Character($cp, $properties);
}
protected function buildGeneralProperties(Block $block = null, GeneralCategory $cat = null, Script $script = null)
{
$cat = $cat ?: new GeneralCategory(GeneralCategory::OTHER_CONTROL);
$script = $script ?: new Script(Script::COMMON);
$age = new Properties\General\Version(Properties\General\Version::V8_0);
$primary = new Properties\General\Name\Assigned('Name');
$names = new Properties\General\Names($primary);
return new Properties\General($names, $block ?: new Block(Block::BASIC_LATIN), $age, $cat, $script);
}
protected function buildLetterCase(Codepoint $cp)
{
$mapping = new Properties\LetterCase\Mapping($cp, [$cp]);
$mappings = new Properties\LetterCase\Mappings($mapping, $mapping, $mapping, $mapping);
return new Properties\LetterCase($mappings);
}
protected function buildNumericity()
{
$numericType = new Properties\Numericity\NumericType(Properties\Numericity\NumericType::NONE);
return new Properties\Numericity\NonNumeric($numericType);
}
protected function buildNormalization()
{
$combining = new Properties\Normalization\Combining(Properties\Normalization\Combining::ABOVE);
$dType = Properties\Normalization\DecompositionType::CANONICAL;
$decompositionType = new Properties\Normalization\DecompositionType($dType);
$decomp = new Properties\Normalization\Decomposition\Assigned($decompositionType, []);
return new Properties\Normalization($combining, $decomp);
}
protected function buildBidirectionality()
{
$classing = new Properties\Bidirectionality\Classing(Properties\Bidirectionality\Classing::COMMON_SEPARATOR);
$mirroring = new Properties\Bidirectionality\Mirroring(true);
return new Properties\Bidirectionality($classing, $mirroring, true);
}
protected function buildShaping()
{
$joiningGroup = new Properties\Shaping\JoiningGroup(Properties\Shaping\JoiningGroup::NO_JOINING_GROUP);
$joiningType = new Properties\Shaping\JoiningType(Properties\Shaping\JoiningType::NON_JOINING);
$joining = new Properties\Shaping\Joining($joiningGroup, $joiningType, false);
return new Properties\Shaping($joining);
}
}