Created
April 29, 2024 15:28
-
-
Save leecolarelli/6a4326ee32cfd588861893448e5234ac to your computer and use it in GitHub Desktop.
Example Laravel route to controller action test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| use App\Http\Controllers\Api\Bigcommerce\Store\ApiBigcommerceStoreCustomerController; | |
| use App\Models\Store\Store; | |
| use Illuminate\Support\Facades\Schema; | |
| use function Pest\Laravel\{post}; | |
| /** api.bigcommerce.stores.customers.store */ | |
| it( | |
| 'correctly defines the route to store@ApiBigcommerceStoreCustomerController', | |
| function (): void { | |
| Schema::disableForeignKeyConstraints(); | |
| $store = Store::factory()->createOne(['owner_id' => 1, 'hash' => 'abc123']); | |
| $customer = [ | |
| 'bigcommerce_id' => 12345, | |
| 'first_name' => 'Peter', | |
| 'last_name' => 'Parker', | |
| 'email' => '[email protected]', | |
| 'customer_group_id' => 1, | |
| ]; | |
| $route = route('api.bigcommerce.stores.customers.store', [$store->hash]); | |
| expect($route)->toBe('https://thegelbottle-bigcommerce.test/api/bigcommerce/stores/abc123/customers'); | |
| $mockController = Mockery::mock(ApiBigcommerceStoreCustomerController::class . '[callAction]'); | |
| app()->instance(ApiBigcommerceStoreCustomerController::class, $mockController); | |
| /** @phpstan-ignore-next-line */ | |
| $mockController->shouldReceive('callAction')->withArgs(['store', Mockery::any()])->once(); | |
| post($route, $customer)->assertStatus(200); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment