Skip to content

Commit 1efc502

Browse files
committed
[minor] throw helpful exception if using service stories without bundle
1 parent a5d4154 commit 1efc502

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/StoryManager.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ private function getOrCreateStory(string $class): Story
6666
}
6767
}
6868

69-
return new $class();
69+
try {
70+
return new $class();
71+
} catch (\ArgumentCountError $e) {
72+
throw new \RuntimeException('Stories with dependencies (Story services) cannot be used without the foundry bundle.', 0, $e);
73+
}
7074
}
7175
}

tests/Functional/StoryTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,19 @@ public function stories_can_be_services(): void
6868

6969
$this->assertSame('From Service', ServiceStory::post()->getTitle());
7070
}
71+
72+
/**
73+
* @test
74+
*/
75+
public function service_stories_cannot_be_used_without_the_bundle(): void
76+
{
77+
if (\getenv('USE_FOUNDRY_BUNDLE')) {
78+
$this->markTestSkipped('ZenstruckFoundryBundle enabled.');
79+
}
80+
81+
$this->expectException(\RuntimeException::class);
82+
$this->expectExceptionMessage('Stories with dependencies (Story services) cannot be used without the foundry bundle.');
83+
84+
ServiceStory::load();
85+
}
7186
}

0 commit comments

Comments
 (0)