Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Api Platform Test Laravel Package

l0wskilled/api-platform-test

View on GitHub
Deep Wiki
Context7

API Platform Test

Bundle to ease the test of Endpoints generated by ApiPlatform.

You may want to have a look at: https://github.com/epubli/api-platform-traits

Usage

If you want a simple CRUD Testing for your entity just extend the ApiPlatformTestCase and override the endpoint and the resource class

/** Endpoint to test (override in your testcase) */
protected const RESOURCE_URI = '/';
/** Entity class to test (override in your testcase) */
protected const RESOURCE_CLASS = '';
ORM only

Since v0.3.0 we only support ORM.

ORM Example Test class
class ExampleTest extends ApiPlatformTestCase
{

    protected const RESOURCE_URI = '/api/example/';
    protected const RESOURCE_CLASS = Example::class;

    protected function getTestEntity(): Example
    {
        $example = new Example();
        $example->setLocale(static::$faker->countryCode());
        $example->setStandard(false);
        $example->setTitle(static::$faker->country());
        return $example;
    }

}

With this setup common CRUD-Tests will be executed.

If you want to adjust the behaviour of some Test-Cases just override the default Test-Case

For e.g.

    public function testReadAResourceCollection(): void
    {
        parent::testReadAResourceCollection();
        $this->assertCollectionCount(3);
    }

    public function testReadAResource(): void
    {
        parent::testReadAResource();
        $this->assertResourcePropertyCount(10);
    }

During the testing the entities get serialized by the symfony serializer. This can serialize attributes you don't want to compare, especially if you have circular references.

For this case you can provide a list of ignored attributes. These will be skipped during serialization.

    protected function getIgnoredAttributes(): array
    {
        return ['children'];
    }

If you do not have all CRUD Operations available you can override the unsupported test with a route not available test to ensure this.

    public function testCreateAResource(): void
    {
        $this->testThrowErrorWhenRouteIsForbidden();
        parent::testCreateAResource();
    }
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
elmogy/larafast
xeviant/laravel-paystack
gorilladash/laravel-website-sdk
martialbe/flysystem-oss
chondal/3312client
jeroen-g/flickr
opscale-co/nova-genbi
itsjustvita/laravel-retention
tequilarapido/trackit
gregsphotography/site-builder-filament
cabaoctavio/laravel-query-log
gregsphotography/site-builder-components
io-digital/clickatell
snowsoft/laravel-admin
oxygen/auth
relicsoftware/barakah-payment-gateway
tobya/work-with-composer
equipc/laravel-email-validator
equipc/laravel-email-database-log
adedsec/nova-translated-labels