Skip to content

Commit 477ef99

Browse files
authored
Fixed absolute path detection (#8)
* Fixed absolute path detection * Added folder for tests in scrutinizer * Trying to fix the regex * Fixed issue with regex and added unit test * Removed capturing group
1 parent b3dd459 commit 477ef99

File tree

4 files changed

+47
-16
lines changed

4 files changed

+47
-16
lines changed

src/Module/Phiremock.php

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public function __construct(ModuleContainer $moduleContainer, $config = null, bo
6363
}
6464

6565
/**
66+
* @param mixed $settings
6667
* @throws ConfigurationException
6768
* @throws Exception
6869
*/
@@ -174,9 +175,22 @@ public function setScenarioState(string $name, string $state): void
174175
$this->phiremock->setScenarioState($name, $state);
175176
}
176177

178+
/** @throws ModuleException */
179+
protected function setupExtraConnections(): void
180+
{
181+
if (!$this->isExtraConfig) {
182+
foreach ($this->moduleConfig->getExtraConnectionsConfigs() as $name => $connectionConfig) {
183+
if ($name === 'default') {
184+
throw new ModuleException($this, 'The connection name "default" is reserved and can not be used for an extra connection');
185+
}
186+
$this->extraConnections[$name] = new self($this->moduleContainer, $connectionConfig->asArray(), true);
187+
}
188+
}
189+
}
190+
177191
private function createDebugMethod(): callable
178192
{
179-
return function (string $msg) : void {
193+
return function (string $msg): void {
180194
$this->debug($msg);
181195
};
182196
}
@@ -225,17 +239,4 @@ private function extraConfigsBefore(TestInterface $test): void
225239
}
226240
}
227241
}
228-
229-
/** @throws ModuleException */
230-
protected function setupExtraConnections(): void
231-
{
232-
if (!$this->isExtraConfig) {
233-
foreach ($this->moduleConfig->getExtraConnectionsConfigs() as $name => $connectionConfig) {
234-
if ($name === 'default') {
235-
throw new ModuleException($this, 'The connection name "default" is reserved and can not be used for an extra connection');
236-
}
237-
$this->extraConnections[$name] = new self($this->moduleContainer, $connectionConfig->asArray(), true);
238-
}
239-
}
240-
}
241242
}

src/Util/Config.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ public function __construct(array $config, callable $output)
6767
$this->clientFactory = $this->getFactoryClass($config);
6868
$this->initExtraConnections($config);
6969
$this->secure = $config['secure'];
70-
7170
}
7271

7372
/** @return Config[] */

src/Util/DirectoryPath.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public static function createAndGetInstance(string $path): self
5555
/** @throws ConfigurationException */
5656
public static function createAbsoluteOrRelativeToCodeceptionDir(string $path): self
5757
{
58-
if (substr($path, 0, 1) === '/') {
58+
if (preg_match('~^(?:[a-z]:\\\|/)~i', $path) === 1) {
5959
return new self($path);
6060
}
6161
return new self(Configuration::projectDir() . $path);

tests/unit/DirectoryPathCest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
use Codeception\Exception\ConfigurationException;
4+
use Mcustiel\Phiremock\Codeception\Util\DirectoryPath;
5+
6+
class DirectoryPathCest
7+
{
8+
public function testWindowsFullPath(UnitTester $I): void
9+
{
10+
try {
11+
DirectoryPath::createAbsoluteOrRelativeToCodeceptionDir('C:\\PotatoPhiremock');
12+
} catch (ConfigurationException $e) {
13+
$I->assertSame(
14+
'Could not find the configured expectations path: C:\\PotatoPhiremock',
15+
$e->getMessage()
16+
);
17+
}
18+
}
19+
20+
public function testLinuxFullPath(UnitTester $I): void
21+
{
22+
try {
23+
DirectoryPath::createAbsoluteOrRelativeToCodeceptionDir('/home/phiremock/potato');
24+
} catch (ConfigurationException $e) {
25+
$I->assertSame(
26+
'Could not find the configured expectations path: /home/phiremock/potato',
27+
$e->getMessage()
28+
);
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)