Skip to content

Commit aff9a27

Browse files
committed
add vendor support for remove command
1 parent 75b512e commit aff9a27

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

src/Commands/RemoveCommand.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Themsaid\Langman\Commands;
44

55
use Illuminate\Console\Command;
6+
use Illuminate\Support\Str;
67
use Themsaid\Langman\Manager;
78

89
class RemoveCommand extends Command
@@ -58,12 +59,26 @@ public function handle()
5859
try {
5960
list($file, $key) = explode('.', $this->argument('key'), 2);
6061
} catch (\ErrorException $e) {
61-
$this->error('Could not recognize the key you want to translate.');
62+
$this->error('Could not recognize the key you want to remove.');
6263

6364
return;
6465
}
6566

6667
if ($this->confirm("Are you sure you want to remove \"{$file}.{$key}\"?")) {
68+
if (Str::contains($file, '::')) {
69+
try {
70+
$parts = explode('::', $file);
71+
72+
$this->manager->setPathToVendorPackage($parts[0]);
73+
74+
$file = $parts[1];
75+
} catch (\ErrorException $e) {
76+
$this->error('Could not recognize the package.');
77+
78+
return;
79+
}
80+
}
81+
6782
$this->manager->removeKey($file, $key);
6883

6984
$this->info("{$file}.{$key} was removed successfully.");

tests/RemoveCommandTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,27 @@ public function testRemovesParentOfNestedKeys()
8484
$this->assertArrayNotHasKey('name', $userENFile);
8585
$this->assertArrayNotHasKey('name', $userNLFile);
8686
}
87+
88+
public function testCommandOutputForVendorPackage()
89+
{
90+
$manager = $this->app[Manager::class];
91+
92+
$this->createTempFiles([
93+
'en' => ['user' => "<?php\n return ['weight' => 'weight'];", 'category' => ''],
94+
'nl' => ['user' => '', 'category' => ''],
95+
'vendor' => ['package' => ['en' => ['file' => "<?php\n return ['not_found' => 'file not found here'];"], 'sp' => ['file' => "<?php\n return ['not_found' => 'something'];"]]],
96+
]);
97+
98+
$command = m::mock('\Themsaid\Langman\Commands\RemoveCommand[confirm]', [$manager]);
99+
$command->shouldReceive('confirm')->once()->with('Are you sure you want to remove "package::file.not_found"?')->andReturn(true);
100+
101+
$this->app['artisan']->add($command);
102+
$this->artisan('langman:remove', ['key' => 'package::file.not_found']);
103+
104+
$ENFile = (array) include $this->app['config']['langman.path'].'/vendor/package/en/file.php';
105+
$SPFile = (array) include $this->app['config']['langman.path'].'/vendor/package/sp/file.php';
106+
107+
$this->assertArrayNotHasKey('name', $ENFile);
108+
$this->assertArrayNotHasKey('name', $SPFile);
109+
}
87110
}

0 commit comments

Comments
 (0)