1
+ <?php
2
+
3
+ namespace PHPUnitBenchmarkData ;
4
+
5
+ use Swaggest \JsonSchema \Constraint \Properties ;
6
+ use Swaggest \JsonSchema \Schema ;
7
+ use Swaggest \JsonSchema \Structure \ClassStructure ;
8
+
9
+ class Config extends ClassStructure
10
+ {
11
+ public $ calcPerformanceIndex ;
12
+
13
+ public $ resultPrecision ;
14
+ public $ resultFilename ;
15
+
16
+ /** @var TestConfig */
17
+ public $ defaultTestConfig ;
18
+
19
+ /** @var TestConfig[] map of test name to config */
20
+ public $ testConfigs ;
21
+
22
+ /**
23
+ * @param Properties|static $properties
24
+ * @param Schema $ownerSchema
25
+ * @throws \Exception
26
+ * @throws \Swaggest\JsonSchema\InvalidValue
27
+ */
28
+ public static function setUpProperties ($ properties , Schema $ ownerSchema )
29
+ {
30
+ $ properties ->calcPerformanceIndex = Schema::boolean ()->setDefault (true )
31
+ ->setDescription ('Calc host performance index ' );
32
+
33
+ $ properties ->resultPrecision = Schema::integer ()->setDefault (5 )
34
+ ->setDescription ('Result JSON precision ' );
35
+
36
+ $ properties ->resultFilename = Schema::string ()->setDefault ('benchmark-result.json ' )
37
+ ->setDescription ('Result filename ' );
38
+
39
+ $ defaultTestConfig = new TestConfig ();
40
+ $ defaultTestConfig ->numIterations = 100 ;
41
+ $ properties ->defaultTestConfig = clone TestConfig::schema ();
42
+ $ properties ->defaultTestConfig ->setDefault (TestConfig::export ($ defaultTestConfig ))
43
+ ->setDescription ('Default configuration ' );
44
+
45
+ $ properties ->testConfigs = Schema::object ()->setAdditionalProperties (TestConfig::schema ())
46
+ ->setDescription ('Test settings ' );
47
+ }
48
+
49
+ /**
50
+ * @return static
51
+ * @throws \Exception
52
+ * @throws \Swaggest\JsonSchema\Exception
53
+ * @throws \Swaggest\JsonSchema\InvalidValue
54
+ */
55
+ public static function load ()
56
+ {
57
+ if (file_exists ('phpunit-bench.json ' )) {
58
+ $ config = Config::import (json_decode (file_get_contents ('phpunit-bench.json ' )));
59
+ } else {
60
+ $ config = Config::import (new \stdClass );
61
+ }
62
+ return $ config ;
63
+ }
64
+ }
0 commit comments