Skip to content

Commit 51dd388

Browse files
author
Harry Bragg
authored
make all file paths absolute (#4)
* make all file paths absolute * restore dockerfile
1 parent d5128a8 commit 51dd388

File tree

6 files changed

+24
-12
lines changed

6 files changed

+24
-12
lines changed

src/Command/ChopCommand.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
7676
$config = (new Config())->parse($input->getOption('config'));
7777
$group = $input->getOption('group') ?: $config->get(Config::CONFIG_DEFAULT_GROUP);
7878

79-
$tablePopulator = new TablePopulator(new Local('.'));
79+
$tablePopulator = new TablePopulator(new Local('/'));
8080
$schemaParser = new SchemaParser($tablePopulator, $config, $group);
8181
$parsedSchemas = $schemaParser->extractSchemas($schemas);
8282

@@ -94,10 +94,11 @@ function (ParsedSchema $schema) {
9494

9595
foreach ($parsedSchemas as $schema) {
9696
$output->writeln(sprintf(
97-
'Chopping down <info>%d</info> tables in <info>%s</info> schema in group <info>%s</info>',
97+
'Chopping down <info>%d</info> tables in <info>%s</info> schema in group <info>%s</info> from <info>%s</info>',
9898
count($schema->getTables()),
9999
$schema->getSchemaName(),
100-
$group
100+
$group,
101+
$schema->getPath()
101102
));
102103

103104
if ($useGlobal) {

src/Command/DumpCommand.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
7373
$config = (new Config())->parse($input->getOption('config'));
7474
$group = $input->getOption('group') ?: $config->get(Config::CONFIG_DEFAULT_GROUP);
7575

76-
$fileSystem = new Local('.');
76+
$fileSystem = new Local('/');
7777
$tablePopulator = new TablePopulator($fileSystem);
7878
$schemaParser = new SchemaParser($tablePopulator, $config, $group);
7979
$parsedSchemas = $schemaParser->extractSchemas($schemas);
@@ -92,10 +92,11 @@ function (ParsedSchema $schema) {
9292

9393
foreach ($parsedSchemas as $schema) {
9494
$output->writeln(sprintf(
95-
'Dumping <info>%d</info> tables in <info>%s</info> schema in group <info>%s</info>',
95+
'Dumping <info>%d</info> tables in <info>%s</info> schema in group <info>%s</info> to <info>%s</info>',
9696
count($schema->getTables()),
9797
$schema->getSchemaName(),
98-
$group
98+
$group,
99+
$schema->getPath()
99100
));
100101

101102
if ($useGlobal) {

src/Command/SeedCommand.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
9999
}
100100
}
101101

102-
$tablePopulator = new TablePopulator(new Local('.'));
102+
$tablePopulator = new TablePopulator(new Local('/'));
103103
$schemaParser = new SchemaParser($tablePopulator, $config, $group);
104104
$parsedSchemas = $schemaParser->extractSchemas($schemas);
105105

@@ -117,10 +117,11 @@ function (ParsedSchema $schema) {
117117

118118
foreach ($parsedSchemas as $schema) {
119119
$output->writeln(sprintf(
120-
'Seeding <info>%d</info> tables in <info>%s</info> schema in group <info>%s</info>',
120+
'Seeding <info>%d</info> tables in <info>%s</info> schema in group <info>%s</info> from <info>%s</info>',
121121
count($schema->getTables()),
122122
$schema->getSchemaName(),
123-
$group
123+
$group,
124+
$schema->getPath()
124125
));
125126

126127
if ($useGlobal) {

src/Config/Config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public function getSchemaConfiguration(string $schema): SchemaConfigInterface
155155
public function getSchemaPath(SchemaConfigInterface $schema, string $group = null): string
156156
{
157157
$group = $group ?: $this->get("defaults.group");
158-
return sprintf('%s/%s/', $this->getGroupPath($group), $schema->getDirName());
158+
return realpath(sprintf('%s/%s/', $this->getGroupPath($group), $schema->getDirName()));
159159
}
160160

161161
/**

src/Parser/TablePopulator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function __construct(AdapterInterface $filesystem)
3838
public function populateTables(ParsedSchema $parsedSchema)
3939
{
4040
if (count($parsedSchema->getTables()) === 0) {
41-
if ($this->filesystem->has($parsedSchema->getPath()) === false) {
41+
if ($parsedSchema->getPath() === '' || $this->filesystem->has($parsedSchema->getPath()) === false) {
4242
return null;
4343
}
4444

tests/unit/Parser/TablePopulatorTest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use Graze\Sprout\Config;
66
use Graze\Sprout\Parser\ParsedSchema;
7-
use Graze\Sprout\Parser\SchemaParser;
87
use Graze\Sprout\Parser\TablePopulator;
98
use Graze\Sprout\Test\TestCase;
109
use League\Flysystem\AdapterInterface;
@@ -89,4 +88,14 @@ public function testPopulateTablesWithNoFilesReturnsNull()
8988

9089
$this->assertNull($output);
9190
}
91+
92+
public function testEmptyPathReturnsNull()
93+
{
94+
$config = Mockery::mock(Config\SchemaConfigInterface::class);
95+
$parsedSchema = new ParsedSchema($config, '', []);
96+
97+
$output = $this->schemaParser->populateTables($parsedSchema);
98+
99+
$this->assertNull($output);
100+
}
92101
}

0 commit comments

Comments
 (0)