Felhasználói eszközök

Eszközök a webhelyen


oktatas:web:back-end_framework:leaf:teszt

< Leaf

Leaf Teszt

Telepítés

leaf install alchemy

Beállítás

./vendor/bin/alchemy setup

A konfiguráció a gyökérkönyvtárban:

  • alchemy.config.php

Futtatás

leaf test

Memória adatbázis

Szerkesszük a alchemy.config.php fájlt. Vegyünk fel egy újabb beállítást:

alchemy.config.php
	'connections' => [
		'default' => [
			'driver' => 'sqlite',
			'database' => ':memory:',
			'prefix' => ''
		]
	]

Tesztírás

HTTP kéréseket kell készítenünk. Bármilyen PHP-s eszköz megfelel. Itt CURL fogunk alkalmazni.

tests/app.test.php
<?php
 
function make_request($url, $method = 'GET', $data = []) {
	$ch = curl_init($url);
 
	// A válasz ne a képernyőre menjen:
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	// Ha szerver átirányítások végez, kövessük
	curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
 
	$method = strtoupper($method);
	switch ($method) {
		case 'GET':
			break;
		case 'POST':
			curl_setopt($ch, CURLOPT_POST, true);
			curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
			break;
		case 'PUT':
			curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
			curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
			break;
		case 'DELETE':
			curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
			break;
		default:
			// Egyéb metódusok
			break;
	}
 
	$response = curl_exec($ch);
	$http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
	curl_close($ch);
 
	return $http_status;
}
 
 
test('get employees tesztelése', function () {
	$url = 'http://localhost:5500/employees';
	$http_status = make_request($url);
	expect($http_status)->toBe(200);
});
test('post employees tesztelése', function () {
	$url = 'http://localhost:5500/employees';
	$post_data = [
		'name' => 'Valaki',
		'city' => 'Valahol',
		'salary' => 500
	];	
	$http_status = make_request($url, 'POST', $post_data);
	expect($http_status)->toBe(200);
});
test('put employees tesztelése', function () {
	$url = 'http://localhost:5500/employees/0';
	$post_data = [
		'name' => 'Másvalaki',
		'city' => 'Máshol',
		'salary' => 352
	];	
	$http_status = make_request($url, 'PUT', $post_data);
	expect($http_status)->toBe(200);
});
test('delete employees tesztelése', function () {
	$url = 'http://localhost:5500/employees/0';
	$http_status = make_request($url, 'DELETE');
	expect($http_status)->toBe(200);
});
oktatas/web/back-end_framework/leaf/teszt.txt · Utolsó módosítás: 2024/01/26 08:55 szerkesztette: admin