Skip to content

Commit 6acf08d

Browse files
TofandelAidasK
authored andcommitted
Fix getBaseNamespace (area17#2420)
* Fix getBaseNamespace * Add tests * Given getBasePath is broken and not used anywhere, remove it * Fix tests * Update CapsulesTest.php
1 parent e418398 commit 6acf08d

File tree

2 files changed

+6
-15
lines changed

2 files changed

+6
-15
lines changed

src/Helpers/Capsule.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,6 @@ public function loadTranslations(): void
111111
}
112112
}
113113

114-
public function getBasePath(string $path): string
115-
{
116-
$exploded = explode(DIRECTORY_SEPARATOR, $path);
117-
118-
return implode(DIRECTORY_SEPARATOR, array_pop($exploded));
119-
}
120-
121114
public function getModule(): string
122115
{
123116
return Str::camel($this->name);
@@ -142,7 +135,7 @@ public function getBaseNamespace(): string
142135
{
143136
$explodedNamespace = explode('\\', $this->namespace);
144137

145-
return implode('\\', array_pop($explodedNamespace));
138+
return implode('\\', array_slice($explodedNamespace, 0, -1));
146139
}
147140

148141
public function getDatabaseNamespace(): string

tests/integration/Capsules/CapsulesTest.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,11 @@ public function getPackageProviders($app)
8787
*/
8888
public function testCapsuleProviderWasRegistered()
8989
{
90-
class_exists(
91-
"App\Twill\Capsules\{$this->capsuleClassName}\Models\{$this->capsuleModelName}"
92-
);
93-
94-
class_exists('A17\Twill\Services\Modules\HasModules');
95-
96-
// @todo: Validate this test.
90+
$capsule = TwillCapsules::getCapsuleForModule($this->capsuleName);
91+
92+
$this->assertTrue(class_exists("{$capsule->getModelNamespace()}\\{$this->capsuleModelName}"));
93+
$this->assertEquals("App\\Twill\\Capsules", $capsule->getBaseNamespace());
94+
$this->assertEquals("App\\Twill\\Capsules\\".$this->capsuleClassName, $capsule->namespace);
9795
}
9896

9997
/**

0 commit comments

Comments
 (0)