Felhasználói eszközök

Eszközök a webhelyen


oktatas:web:back-end_framework:leaf:teszt

Különbségek

A kiválasztott változat és az aktuális verzió közötti különbségek a következők.

Összehasonlító nézet linkje

Előző változat mindkét oldalonElőző változat
Következő változat
Előző változat
oktatas:web:back-end_framework:leaf:teszt [2024/01/25 22:45] – [Beállítás] adminoktatas:web:back-end_framework:leaf:teszt [2024/01/26 08:55] (aktuális) – [Memória adatbázis] admin
Sor 24: Sor 24:
  
   leaf test   leaf test
 +
 +===== Memória adatbázis =====
 +
 +
 +Szerkesszük a alchemy.config.php fájlt. Vegyünk fel egy újabb beállítást:
 +
 +<code php alchemy.config.php>
 + 'connections' => [
 + 'default' => [
 + 'driver' => 'sqlite',
 + 'database' => ':memory:',
 + 'prefix' => ''
 + ]
 + ]
 +</code>
 +
 +
 +===== Tesztírás =====
 +
 +HTTP kéréseket kell készítenünk. Bármilyen PHP-s eszköz megfelel. Itt CURL fogunk alkalmazni.
 +
 +<code php 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);
 +});
 +
 +
 +
 +</code>
  
oktatas/web/back-end_framework/leaf/teszt.1706219135.txt.gz · Utolsó módosítás: 2024/01/25 22:45 szerkesztette: admin