ssaweb/appwrite-test-utils

Helpful classes to write your PHPUnit tests for Appwrite functions

v2.0.2 2024-01-08 04:40 UTC

This package is auto-updated.

Last update: 2024-05-08 05:16:54 UTC


README

Classes to help you writing your PHPUnit tests for Appwrite functions

Why use a $context wrapper?

Personal needs that may be useful to someone else XD

Basically if you try to write a test to check the data sent to the json or send methods of Appwrite Functions' API like below:

$this->response = $this->createMock(stdClass::class);

$this->response
    ->expects($this->once())
    ->method('json')
    ->with($this->anything(), 201);

The code above will fail with the following message:

Trying to configure method "json" which cannot be configured because it does not exist, has not been specified, is final, or is static

Therefore, we need to add a type to that object, since Appwrite's SDK does not provide it to us, I've created this package to do so.

$this->response = $this->createMock(Response::class);

$this->response
    ->expects($this->once())
    ->method('json')
    ->with($this->anything(), 201);

now we've a typed $response object that can be evaluated =)