Skip to content

Commit 45fbab4

Browse files
committed
Дописал тестов
1 parent 3628f0c commit 45fbab4

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ $entitiesPath = CMS_FOLDER . 'modules';
3131
$adminEntitiesPath = CMS_FOLDER . 'adminentities';
3232
3333
$metaGenerator = new MetaGenerator($phpStormMetaFilePath);
34-
$metaGenerator->addDriver(new EntitiesDriver($entitiesPath)) // Add entities driver
35-
->addDriver(new AdminEntitiesDriver($adminEntitiesPath)) // Add admin-entities driver
34+
$metaGenerator->addDriver(new DriverEntities($entitiesPath)) // Add entities driver
35+
->addDriver(new DriverAdminEntities($adminEntitiesPath)) // Add admin-entities driver
3636
->scan()
3737
->printFile();
3838
```

src/PhpStormMetaGenerator/MetaGenerator.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,12 @@ public function render()
114114
*/
115115
public function setMetaFilePath($metaFilePath)
116116
{
117+
if (!is_string($metaFilePath)) {
118+
throw new InvalidArgumentException('Meta-file path must be a string.');
119+
}
120+
117121
$dirName = dirname($metaFilePath);
118-
if (!file_exists($dirName) || !is_dir($dirName)) {
122+
if (!is_dir($dirName)) {
119123
throw new InvalidArgumentException('Invalid file path.');
120124
}
121125

tests/MetaGeneratorTest.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,19 @@ public function testMetaFilePath()
2222
$this->assertEquals($metaGenerator->getMetaFilePath(), 'path1');
2323
$metaGenerator->setMetaFilePath('path2');
2424
$this->assertEquals($metaGenerator->getMetaFilePath(), 'path2');
25+
26+
$throw = false;
27+
try {
28+
$metaGenerator->setMetaFilePath(1);
29+
} catch(InvalidArgumentException $e) {
30+
$throw = true;
31+
}
32+
if (!$throw) {
33+
$this->fail('Set meta-file path exception is not thrown.');
34+
}
2535
}
2636

27-
public function testNamespaces()
37+
public function testDrivers()
2838
{
2939
$metaGenerator = new MetaGenerator($this->metaFilePath);
3040
$this->assertTrue(empty($metaGenerator->getDrivers()));
@@ -39,4 +49,13 @@ public function testNamespaces()
3949
$this->assertSame($metaGenerator->getDrivers()[1], $secondDriver);
4050
}
4151

52+
public function testScan()
53+
{
54+
$metaGenerator = new MetaGenerator($this->metaFilePath);
55+
$metaGenerator->addDriver(new DriverEntities($this->entitiesRoot))
56+
->addDriver(new DriverAdminEntities($this->adminEntitiesRoot));
57+
$this->assertSame($metaGenerator->scan(), $metaGenerator);
58+
$this->assertEquals($metaGenerator->get(), file_get_contents(__DIR__ . '/data/hostcms/.phpstorm.meta.php'));
59+
}
60+
4261
}

0 commit comments

Comments
 (0)