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
oktatas:web:back-end_framework:leaf:teszt [2024/01/26 08:52] – [Futtatás] adminoktatas:web:back-end_framework:leaf:teszt [2024/01/26 08:55] (aktuális) – [Memória adatbázis] admin
Sor 38: Sor 38:
  ]  ]
  ]  ]
 +</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> </code>
  
oktatas/web/back-end_framework/leaf/teszt.1706255568.txt.gz · Utolsó módosítás: 2024/01/26 08:52 szerkesztette: admin