Skip to content

Commit a95a60f

Browse files
authored
Modernize test autoloading for a more PHP-native configuration (#3)
1 parent a88edc7 commit a95a60f

17 files changed

+33
-98
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"Featurevisor\\": "src/"
3030
},
3131
"files": [
32-
"src/index.php"
32+
"src/functions.php"
3333
]
3434
},
3535
"autoload-dev": {
@@ -46,7 +46,7 @@
4646
"featurevisor"
4747
],
4848
"scripts": {
49-
"test": "phpunit --bootstrap tests/bootstrap.php tests"
49+
"test": "phpunit tests"
5050
},
5151
"license": [
5252
"MIT"

featurevisor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
<?php
33

44
require __DIR__ . '/vendor/autoload.php';
5-
require __DIR__ . '/src/index.php';
65

76
use function Featurevisor\createInstance;
87

@@ -471,6 +470,7 @@ function assessDistribution(array $cliOptions) {
471470
$populateUuid = $cliOptions['populateUuid'];
472471

473472
$datafilesByEnvironment = buildDatafiles($featurevisorProjectPath, [$cliOptions['environment']]);
473+
$level = getLoggerLevel($cliOptions);
474474

475475
$f = createInstance([
476476
'datafile' => $datafilesByEnvironment[$cliOptions['environment']],

phpunit.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
33
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
4-
bootstrap="tests/bootstrap.php"
54
colors="true"
65
processIsolation="false"
76
stopOnFailure="false"

src/Instance.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,3 @@ public function getAllEvaluations(array $context = [], array $featureKeys = [],
380380
return $evaluations;
381381
}
382382
}
383-
384-
function createInstance(array $options = []): Instance
385-
{
386-
return new Instance($options);
387-
}

src/Logger.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,3 @@ public static function defaultLogHandler(string $level, string $message, $detail
7474
echo PHP_EOL;
7575
}
7676
}
77-
78-
function createLogger(array $options = []): Logger
79-
{
80-
return new Logger($options);
81-
}

src/functions.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Featurevisor;
4+
5+
function createInstance(array $options = []): Instance
6+
{
7+
return new Instance($options);
8+
}
9+
10+
function createLogger(array $options = []): Logger
11+
{
12+
return new Logger($options);
13+
}

src/index.php

Lines changed: 0 additions & 42 deletions
This file was deleted.

tests/BucketerTest.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
<?php
22

3+
namespace Featurevisor\Tests;
4+
35
use PHPUnit\Framework\TestCase;
4-
require_once __DIR__ . '/../src/Bucketer.php';
5-
require_once __DIR__ . '/../src/Logger.php';
66

77
use Featurevisor\Bucketer;
8-
use Featurevisor\Logger;
98
use function Featurevisor\createLogger;
109

1110
class BucketerTest extends TestCase {
12-
public function testGetBucketedNumberIsFunction() {
13-
// In PHP, it's a static method
14-
$this->assertTrue(is_callable([Bucketer::class, 'getBucketedNumber']));
15-
}
1611

1712
public function testGetBucketedNumberRange() {
1813
$keys = ['foo', 'bar', 'baz', '123adshlk348-93asdlk'];

tests/ChildTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
<?php
22

3+
namespace Featurevisor\Tests;
4+
35
use PHPUnit\Framework\TestCase;
4-
require_once __DIR__ . '/../src/Child.php';
5-
require_once __DIR__ . '/../src/Instance.php';
6-
require_once __DIR__ . '/../src/index.php';
76

87
use function Featurevisor\createInstance;
98

tests/ConditionsTest.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php
22

3+
namespace Featurevisor\Tests;
4+
5+
use DateTime;
36
use PHPUnit\Framework\TestCase;
4-
require_once __DIR__ . '/../src/Conditions.php';
5-
require_once __DIR__ . '/../src/DatafileReader.php';
6-
require_once __DIR__ . '/../src/Logger.php';
77

88
use Featurevisor\DatafileReader;
99
use function Featurevisor\createLogger;
@@ -24,10 +24,6 @@ protected function setUp(): void {
2424
]);
2525
}
2626

27-
public function testAllConditionsAreMatchedIsFunction() {
28-
$this->assertTrue(is_callable([$this->datafileReader, 'allConditionsAreMatched']));
29-
}
30-
3127
public function testMatchAllViaStar() {
3228
$this->assertTrue($this->datafileReader->allConditionsAreMatched('*', ['browser_type' => 'chrome']));
3329
$this->assertFalse($this->datafileReader->allConditionsAreMatched('blah', ['browser_type' => 'chrome']));

0 commit comments

Comments
 (0)