✨ Story 3.1: data projects json
This commit is contained in:
34
tests/projects.test.php
Normal file
34
tests/projects.test.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../includes/functions.php';
|
||||
|
||||
function assertTrue($cond, $msg) {
|
||||
if (!$cond) {
|
||||
fwrite(STDERR, $msg . PHP_EOL);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
$projects = getProjects();
|
||||
assertTrue(is_array($projects), 'getProjects not array');
|
||||
assertTrue(count($projects) >= 2, 'expected at least 2 projects');
|
||||
|
||||
$featured = getProjectsByCategory('vedette');
|
||||
assertTrue(count($featured) >= 1, 'expected featured projects');
|
||||
|
||||
$found = getProjectBySlug('ecommerce-xyz');
|
||||
assertTrue(is_array($found), 'project ecommerce-xyz not found');
|
||||
assertTrue(($found['slug'] ?? '') === 'ecommerce-xyz', 'slug mismatch');
|
||||
|
||||
$missing = getProjectBySlug('inexistant');
|
||||
assertTrue($missing === null, 'missing project should be null');
|
||||
|
||||
$missingData = loadJsonData('missing.json');
|
||||
assertTrue($missingData === [], 'missing.json should return empty array');
|
||||
|
||||
$invalidPath = __DIR__ . '/../data/__invalid.json';
|
||||
file_put_contents($invalidPath, '{invalid json');
|
||||
$invalidData = loadJsonData('__invalid.json');
|
||||
@unlink($invalidPath);
|
||||
assertTrue($invalidData === [], 'invalid json should return empty array');
|
||||
|
||||
fwrite(STDOUT, "OK\n");
|
||||
Reference in New Issue
Block a user