spiral/testing
Testing SDK for Spiral Framework packages. Provides a custom TestCase with a TestApp so you can test packages without a full application setup. Configure root directory and bootloaders, and keep test app config under tests/app. PHP 8.1+, Spiral 3.15+.
Full Changelog: https://github.com/spiral/testing/compare/2.12.1...2.12.2
Full Changelog: https://github.com/spiral/testing/compare/2.12.0...2.12.1
Container->hasBinding() in assertContainerBound() by @roxblnfk in https://github.com/spiral/testing/pull/84Full Changelog: https://github.com/spiral/testing/compare/2.11.0...2.12.0
Full Changelog: https://github.com/spiral/testing/compare/2.10.0...2.11.0
Full Changelog: https://github.com/spiral/testing/compare/2.9.1...2.10.0
Full Changelog: https://github.com/spiral/testing/compare/2.9.0...2.9.1
FakeHttp middleware methods by @roxblnfk in https://github.com/spiral/testing/pull/78
FakeHttp::withoutMiddleware in case of scoped middlewareFakeHttp::withMiddlewareFull Changelog: https://github.com/spiral/testing/compare/2.8.3...2.9.0
Full Changelog: https://github.com/spiral/testing/compare/2.8.2...2.8.3
Full Changelog: https://github.com/spiral/testing/compare/2.8.1...2.8.2
http scope by @roxblnfk in https://github.com/spiral/testing/pull/74Full Changelog: https://github.com/spiral/testing/compare/2.8.0...2.8.1
use Spiral\Testing\Attribute\TestScope;
use Spiral\Testing\Tests\TestCase;
final class ExampleTest extends TestCase
{
#[TestScope('http')]
public function testIndexAction(): void
{
$response = $this->fakeHttp()->get('/');
$response->assertOk();
}
}
Full Changelog: https://github.com/spiral/testing/compare/2.7.0...2.8.0
Full Changelog: https://github.com/spiral/testing/compare/2.6.4...2.7.0
Full Changelog: https://github.com/spiral/testing/compare/2.6.3...2.6.4
Full Changelog: https://github.com/spiral/testing/compare/2.6.2...2.6.3
Full Changelog: https://github.com/spiral/testing/compare/2.6.1...2.6.2
Full Changelog: https://github.com/spiral/testing/compare/2.6.0...2.6.1
ServerRequest and Uri by @butschster in https://github.com/spiral/testing/pull/63Full Changelog: https://github.com/spiral/testing/compare/2.5.0...2.6.0
getJsonParsedBody by @gam6itko in https://github.com/spiral/testing/pull/61Full Changelog: https://github.com/spiral/testing/compare/2.4.1...2.5.0
Full Changelog: https://github.com/spiral/testing/compare/2.4.0...2.4.1
Full Changelog: https://github.com/spiral/testing/compare/2.3.1...2.4.0
Full Changelog: https://github.com/spiral/testing/compare/2.3.0...2.3.1
patch and patchJson by @gam6itko in https://github.com/spiral/testing/pull/35TestCase::getApp returns TestableKernelInterface by @gam6itko in https://github.com/spiral/testing/pull/37TestCase remove final from public methods by @gam6itko in https://github.com/spiral/testing/pull/40json request header names by @gam6itko in https://github.com/spiral/testing/pull/39TestCase::getApp - init app on first run. by @gam6itko in https://github.com/spiral/testing/pull/36FakeEventDispatcher::dispatch method, when application doesn't have EventDispatcher implementation by @butschster in https://github.com/spiral/testing/pull/51Full Changelog: https://github.com/spiral/testing/compare/2.2.0...2.3.0
config/http.php
return [
'basePath' => '/',
'headers' => [
'Content-Type' => 'text/html; charset=UTF-8',
],
'middleware' => [],
];
$this->assertConfigHasFragments('http', [
'basePath' => '/'
]);
$this->assertConfigHasFragments('http', [
'headers' => [
'Content-Type' => 'text/html; charset=UTF-8',
],
]);
Full Changelog: https://github.com/spiral/testing/compare/2.1.0...2.2.0
protected function setUp(): void
{
parent::setUp();
$this->eventDispatcher = $this->fakeEventDispatcher();
}
Assert if an event has a listener attached to it.
$this->eventDispatcher->assertListening(SomeEvent::class, SomeListener::class);
Assert if an event was dispatched based on a truth-test callback.
// Assert if an event dispatched one or more times
$this->eventDispatcher->assertDispatched(SomeEvent::class);
// Assert if an event dispatched one or more times based on a truth-test callback.
$this->eventDispatcher->assertDispatched(SomeEvent::class, static function(SomeEvent $event): bool {
return $event->someParam === 100;
});
Assert if an event was dispatched a number of times.
$this->eventDispatcher->assertDispatchedTimes(SomeEvent::class, 5);
Determine if an event was dispatched based on a truth-test callback.
$this->eventDispatcher->assertNotDispatched(SomeEvent::class);
$this->eventDispatcher->assertNotDispatched(SomeEvent::class, static function(SomeEvent $event): bool {
return $event->someParam === 100;
});
Assert that no events were dispatched.
$this->eventDispatcher->assertNothingDispatched();
Get all the events matching a truth-test callback.
$this->eventDispatcher->dispatched(SomeEvent::class);
// or
$this->eventDispatcher->dispatched(SomeEvent::class, static function(SomeEvent $event): bool {
return $event->someParam === 100;
});
$this->eventDispatcher->hasDispatched(SomeEvent::class);
Full Changelog: https://github.com/spiral/testing/compare/2.0.0...2.1.0
Full Changelog: https://github.com/spiral/testing/compare/1.2.1...2.0.0
Full Changelog: https://github.com/spiral/testing/compare/1.2.1...1.3.0
Full Changelog: https://github.com/spiral/testing/compare/1.2.1...2.0.0
$http = $this->fakeHttp();
// Create a file with size - 100kb
$file = $http->getFileFactory()->createFile('foo.txt', 100);
// Create a file with specific content
$file = $http->getFileFactory()->createFileWithContent('foo.txt', 'Hello world');
// Create a fake image 640x480
$image = $http->getFileFactory()->createImage('fake.jpg', 640, 480);
$http->post(uri: '/', files: ['avatar' => $image, 'documents' => [$file]])->assertOk();
// Will replace all buckets into with local adapters
$storage = $this->fakeStorage();
// Do something with storage
// $image = new UploadedFile(...);
// $storage->bucket('uploads')->write(
// $image->getClientFilename(),
// $image->getStream()
// );
$uploads = $storage->bucket('uploads');
$uploads->assertExists('image.jpg');
$uploads->assertCreated('image.jpg');
$public = $storage->bucket('public');
$public->assertNotExist('image.jpg');
$public->assertNotCreated('image.jpg');
// $public->delete('file.txt');
$public->assertDeleted('file.txt');
$uploads->assertNotDeleted('file.txt');
$public->assertNotExist('file.txt');
// $public->move('file.txt', 'folder/file.txt');
$public->assertMoved('file.txt', 'folder/file.txt');
$uploads->assertNotMoved('file.txt', 'folder/file.txt');
// $public->copy('file.txt', 'folder/file.txt');
$public->assertCopied('file.txt', 'folder/file.txt');
$uploads->assertNotCopied('file.txt', 'folder/file.txt');
// $public->setVisibility('file.txt', 'public');
$public->assertVisibilityChanged('file.txt');
$uploads->assertVisibilityNotChanged('file.txt');
Full Changelog: https://github.com/spiral/testing/compare/1.1.1...1.2
Full Changelog: https://github.com/spiral/testing/compare/1.1.0...1.1.1
How can I help you explore Laravel packages today?