Procházet zdrojové kódy

.phpunit.result.cache ignored

Andreas von Burg před 1 měsícem
rodič
revize
17581c5134

+ 47 - 45
composer.lock

@@ -149,12 +149,12 @@
             "source": {
                 "type": "git",
                 "url": "https://github.com/n2n/n2n.git",
-                "reference": "4ae43658a549ed5989c19fd7827069abaa4438c1"
+                "reference": "c8ca39047666302845c84c3e1816426f9682fb81"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/n2n/n2n/zipball/4ae43658a549ed5989c19fd7827069abaa4438c1",
-                "reference": "4ae43658a549ed5989c19fd7827069abaa4438c1",
+                "url": "https://api.github.com/repos/n2n/n2n/zipball/c8ca39047666302845c84c3e1816426f9682fb81",
+                "reference": "c8ca39047666302845c84c3e1816426f9682fb81",
                 "shasum": ""
             },
             "require": {
@@ -213,7 +213,7 @@
                 "issues": "https://github.com/n2n/n2n/issues",
                 "source": "https://github.com/n2n/n2n/tree/7.5.x"
             },
-            "time": "2026-07-31T13:25:46+00:00"
+            "time": "2026-10-05T11:21:20+00:00"
         },
         {
             "name": "n2n/n2n-batch",
@@ -275,12 +275,12 @@
             "source": {
                 "type": "git",
                 "url": "https://github.com/n2n/n2n-bind.git",
-                "reference": "c2dc87bca8182385efd732bcc112a1836c7488c1"
+                "reference": "7a7833e00eeab8151676d0f993bb82a1d4408c5b"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/n2n/n2n-bind/zipball/c2dc87bca8182385efd732bcc112a1836c7488c1",
-                "reference": "c2dc87bca8182385efd732bcc112a1836c7488c1",
+                "url": "https://api.github.com/repos/n2n/n2n-bind/zipball/7a7833e00eeab8151676d0f993bb82a1d4408c5b",
+                "reference": "7a7833e00eeab8151676d0f993bb82a1d4408c5b",
                 "shasum": ""
             },
             "require": {
@@ -293,6 +293,7 @@
                 "n2n/n2n-validation": "~7.5.0"
             },
             "require-dev": {
+                "n2n/n2n-test": "^7.5",
                 "phpunit/phpunit": "^9.6"
             },
             "type": "library",
@@ -322,20 +323,20 @@
                 "issues": "https://github.com/n2n/n2n-bind/issues",
                 "source": "https://github.com/n2n/n2n-bind/tree/7.5.x"
             },
-            "time": "2026-09-11T22:07:59+00:00"
+            "time": "2026-10-08T15:58:19+00:00"
         },
         {
             "name": "n2n/n2n-cache",
-            "version": "7.5.x-dev",
+            "version": "dev-develop",
             "source": {
                 "type": "git",
                 "url": "https://github.com/n2n/n2n-cache.git",
-                "reference": "6a7a36bc6ee48fcbf45d79cea164823a09e1c03c"
+                "reference": "c954e997b20237898f01ff899bd2a814767d9677"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/n2n/n2n-cache/zipball/6a7a36bc6ee48fcbf45d79cea164823a09e1c03c",
-                "reference": "6a7a36bc6ee48fcbf45d79cea164823a09e1c03c",
+                "url": "https://api.github.com/repos/n2n/n2n-cache/zipball/c954e997b20237898f01ff899bd2a814767d9677",
+                "reference": "c954e997b20237898f01ff899bd2a814767d9677",
                 "shasum": ""
             },
             "require": {
@@ -350,7 +351,7 @@
                 "ext-ctype": "*",
                 "ext-mbstring": "*",
                 "n2n/n2n-impl-persistence-meta": "^7.5.0",
-                "n2n/n2n-test": "^7.4",
+                "n2n/n2n-test": "^7.5",
                 "phpunit/phpunit": "^9.6.19"
             },
             "suggest": {
@@ -386,9 +387,9 @@
             ],
             "support": {
                 "issues": "https://github.com/n2n/n2n-cache/issues",
-                "source": "https://github.com/n2n/n2n-cache/tree/7.5.x"
+                "source": "https://github.com/n2n/n2n-cache/tree/develop"
             },
-            "time": "2026-01-28T10:13:40+00:00"
+            "time": "2026-10-12T14:31:08+00:00"
         },
         {
             "name": "n2n/n2n-composer-module-installer",
@@ -972,12 +973,12 @@
             "source": {
                 "type": "git",
                 "url": "https://github.com/n2n/n2n-persistence.git",
-                "reference": "f29675d0776f9117d40e10f12ce705ef12c75c44"
+                "reference": "02110465698ec5feb67bc329997aef6992fcf514"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/n2n/n2n-persistence/zipball/f29675d0776f9117d40e10f12ce705ef12c75c44",
-                "reference": "f29675d0776f9117d40e10f12ce705ef12c75c44",
+                "url": "https://api.github.com/repos/n2n/n2n-persistence/zipball/02110465698ec5feb67bc329997aef6992fcf514",
+                "reference": "02110465698ec5feb67bc329997aef6992fcf514",
                 "shasum": ""
             },
             "require": {
@@ -1023,7 +1024,7 @@
                 "issues": "https://github.com/n2n/n2n-persistence/issues",
                 "source": "https://github.com/n2n/n2n-persistence/tree/7.5.x"
             },
-            "time": "2026-05-11T08:58:39+00:00"
+            "time": "2026-10-12T14:01:57+00:00"
         },
         {
             "name": "n2n/n2n-queue",
@@ -1090,12 +1091,12 @@
             "source": {
                 "type": "git",
                 "url": "https://github.com/n2n/n2n-reflection.git",
-                "reference": "7cc3b7bf2bab08f92d41c82f1fbc4bf3a26b15c2"
+                "reference": "8231d2fe474a088b9b107841f11f05e873020dc2"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/n2n/n2n-reflection/zipball/7cc3b7bf2bab08f92d41c82f1fbc4bf3a26b15c2",
-                "reference": "7cc3b7bf2bab08f92d41c82f1fbc4bf3a26b15c2",
+                "url": "https://api.github.com/repos/n2n/n2n-reflection/zipball/8231d2fe474a088b9b107841f11f05e873020dc2",
+                "reference": "8231d2fe474a088b9b107841f11f05e873020dc2",
                 "shasum": ""
             },
             "require": {
@@ -1133,7 +1134,7 @@
                 "issues": "https://github.com/n2n/n2n-reflection/issues",
                 "source": "https://github.com/n2n/n2n-reflection/tree/7.5.x"
             },
-            "time": "2025-11-07T13:11:57+00:00"
+            "time": "2026-10-06T12:37:20+00:00"
         },
         {
             "name": "n2n/n2n-spec-dbo",
@@ -1289,12 +1290,12 @@
             "source": {
                 "type": "git",
                 "url": "https://github.com/n2n/n2n-util.git",
-                "reference": "a9b5e3a6f4fed7e6dbf2add74df6ec405fe00eec"
+                "reference": "3ca054e6b76326f040ea66cc06a40e3514aac10c"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/n2n/n2n-util/zipball/a9b5e3a6f4fed7e6dbf2add74df6ec405fe00eec",
-                "reference": "a9b5e3a6f4fed7e6dbf2add74df6ec405fe00eec",
+                "url": "https://api.github.com/repos/n2n/n2n-util/zipball/3ca054e6b76326f040ea66cc06a40e3514aac10c",
+                "reference": "3ca054e6b76326f040ea66cc06a40e3514aac10c",
                 "shasum": ""
             },
             "require": {
@@ -1302,6 +1303,7 @@
                 "ext-gd": "*",
                 "ext-mbstring": "*",
                 "ext-openssl": "*",
+                "n2n/n2n-spec-valobj": "~1.0.0",
                 "php": ">=8.4",
                 "psr/container": "^2.0",
                 "psr/http-factory": "^1",
@@ -1338,7 +1340,7 @@
                 "issues": "https://github.com/n2n/n2n-util/issues",
                 "source": "https://github.com/n2n/n2n-util/tree/7.5.x"
             },
-            "time": "2026-09-11T14:34:01+00:00"
+            "time": "2026-10-13T13:41:15+00:00"
         },
         {
             "name": "n2n/n2n-util-attr",
@@ -1346,12 +1348,12 @@
             "source": {
                 "type": "git",
                 "url": "https://github.com/n2n/n2n-util-attr.git",
-                "reference": "dc156a1034bc30486165c5494e47c53df9cbd4f9"
+                "reference": "c7947767c294774b365864d8d0fe408200e8fba4"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/n2n/n2n-util-attr/zipball/dc156a1034bc30486165c5494e47c53df9cbd4f9",
-                "reference": "dc156a1034bc30486165c5494e47c53df9cbd4f9",
+                "url": "https://api.github.com/repos/n2n/n2n-util-attr/zipball/c7947767c294774b365864d8d0fe408200e8fba4",
+                "reference": "c7947767c294774b365864d8d0fe408200e8fba4",
                 "shasum": ""
             },
             "require": {
@@ -1394,7 +1396,7 @@
                 "issues": "https://github.com/n2n/n2n-util-attr/issues",
                 "source": "https://github.com/n2n/n2n-util-attr/tree/7.5.x"
             },
-            "time": "2026-07-15T10:04:39+00:00"
+            "time": "2026-10-13T10:56:34+00:00"
         },
         {
             "name": "n2n/n2n-util-crypt",
@@ -1516,12 +1518,12 @@
             "source": {
                 "type": "git",
                 "url": "https://github.com/n2n/n2n-validation.git",
-                "reference": "2319936caa748d199ebc77c32d1054459e0ba601"
+                "reference": "dce3ffada68dec792a111ffc6688ede59651d029"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/n2n/n2n-validation/zipball/2319936caa748d199ebc77c32d1054459e0ba601",
-                "reference": "2319936caa748d199ebc77c32d1054459e0ba601",
+                "url": "https://api.github.com/repos/n2n/n2n-validation/zipball/dce3ffada68dec792a111ffc6688ede59651d029",
+                "reference": "dce3ffada68dec792a111ffc6688ede59651d029",
                 "shasum": ""
             },
             "require": {
@@ -1561,7 +1563,7 @@
                 "issues": "https://github.com/n2n/n2n-validation/issues",
                 "source": "https://github.com/n2n/n2n-validation/tree/7.5.x"
             },
-            "time": "2026-09-11T15:02:21+00:00"
+            "time": "2026-10-13T12:58:35+00:00"
         },
         {
             "name": "n2n/n2n-web",
@@ -2465,12 +2467,12 @@
             "source": {
                 "type": "git",
                 "url": "https://github.com/nikic/PHP-Parser.git",
-                "reference": "93411bf09b25bff03a555cbe64cd25cd20e4b966"
+                "reference": "8d2b672aff65a1a4dbf7936cec27d19f51989412"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/93411bf09b25bff03a555cbe64cd25cd20e4b966",
-                "reference": "93411bf09b25bff03a555cbe64cd25cd20e4b966",
+                "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/8d2b672aff65a1a4dbf7936cec27d19f51989412",
+                "reference": "8d2b672aff65a1a4dbf7936cec27d19f51989412",
                 "shasum": ""
             },
             "require": {
@@ -2515,7 +2517,7 @@
                 "issues": "https://github.com/nikic/PHP-Parser/issues",
                 "source": "https://github.com/nikic/PHP-Parser/tree/master"
             },
-            "time": "2026-09-28T19:31:45+00:00"
+            "time": "2026-10-05T07:07:23+00:00"
         },
         {
             "name": "phar-io/manifest",
@@ -2957,16 +2959,16 @@
         },
         {
             "name": "phpunit/phpunit",
-            "version": "9.6.37",
+            "version": "9.6.38",
             "source": {
                 "type": "git",
                 "url": "https://github.com/sebastianbergmann/phpunit.git",
-                "reference": "aceaa623912caf8e80bffea22fc4103a0a01565f"
+                "reference": "8b5f757e8e92071bfdbfa93943f94f84c4e31007"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/aceaa623912caf8e80bffea22fc4103a0a01565f",
-                "reference": "aceaa623912caf8e80bffea22fc4103a0a01565f",
+                "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/8b5f757e8e92071bfdbfa93943f94f84c4e31007",
+                "reference": "8b5f757e8e92071bfdbfa93943f94f84c4e31007",
                 "shasum": ""
             },
             "require": {
@@ -3040,7 +3042,7 @@
             "support": {
                 "issues": "https://github.com/sebastianbergmann/phpunit/issues",
                 "security": "https://github.com/sebastianbergmann/phpunit/security/policy",
-                "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.37"
+                "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.38"
             },
             "funding": [
                 {
@@ -3048,7 +3050,7 @@
                     "type": "other"
                 }
             ],
-            "time": "2026-09-23T09:59:59+00:00"
+            "time": "2026-10-05T05:44:26+00:00"
         },
         {
             "name": "sebastian/cli-parser",

Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 0 - 0
src-php/.phpunit.result.cache


+ 13 - 15
src-php/app/internship/controller/ArticleApiController.php

@@ -9,6 +9,7 @@ use internship\bo\Article;
 use n2n\validation\plan\ErrorMap;
 use n2n\web\http\BadRequestException;
 use n2n\web\http\PageNotFoundException;
+use n2n\web\http\StatusException;
 
 
 /**
@@ -102,30 +103,27 @@ class ArticleApiController extends ControllerAdapter {
 	 * Speichere einen Artikel.
 	 *
 	 * <ul>
-	 * 	<li>
-	 * 		Der Kategoriename darf nur 'international','national' oder 'sport' sein.
-	 * 		Validiere dies und schmeisse im Fehlerfall eine: {@see BadRequestException}
-	 * 	</li>
-	 * 	<li>
-	 *		Mache eine neue Entity {@see Article} und befülle sie mit den übergebenen Daten.
-	 * 	</li>
+	 *    <li>
+	 *        Der Kategoriename darf nur 'international','national' oder 'sport' sein.
+	 *        Validiere dies und schmeisse im Fehlerfall eine: {@see BadRequestException}
+	 *    </li>
+	 *    <li>
+	 *        Mache eine neue Entity {@see Article} und befülle sie mit den übergebenen Daten.
+	 *    </li>
 	 *  <li>
-	 *		Implementiere eine neue Methode im {@see ArticleDao} und bennene sie "saveArticle".
-	 * 	 </li>
+	 *        Implementiere eine neue Methode im {@see ArticleDao} und bennene sie "saveArticle".
+	 *     </li>
 	 * </ul>
 	 *
 	 * Nenne die Methode {@see saveArticle(Aŋ@rticle $article)}
 	 *
 	 * @return void
+	 * @throws StatusException
 	 */
 	function postDoArticle(ParamBody $body): void {
-		
-
-
-		
 		$bodyData = $body->parseJson();
 		$this->beginTransaction();
-		$this->articleDao->BadRequestExceptionIfs($body, 0);
+		$this->articleDao->badRequestExceptionIfs($body, null);
 		$article = new Article();
 		$article->setTitle($bodyData['title']);
 		$article->setText($bodyData['text']);
@@ -157,7 +155,7 @@ class ArticleApiController extends ControllerAdapter {
 	function putDoArticle(int $articleId, ParamBody $body): void {
 		$this->beginTransaction();
 		$article = $this->articleDao->getArticleById($articleId);
-		$this->articleDao->BadRequestExceptionIfs($body, $articleId);
+		$this->articleDao->badRequestExceptionIfs($body, $articleId);
 		$this->articleDao->saveArticle($article);
 		$this->commit();
 		$this->sendJson($article);

+ 13 - 5
src-php/app/internship/model/ArticleDao.php

@@ -8,6 +8,7 @@ use n2n\persistence\Pdo;
 use n2n\web\http\BadRequestException;
 use n2n\web\http\controller\ParamBody;
 use n2n\web\http\PageNotFoundException;
+use n2n\web\http\StatusException;
 
 
 /**
@@ -55,8 +56,8 @@ class ArticleDao {
 	function getArticleById(int $id): ?Article {
 		return $this->em->find(Article::getClass(), $id);
 
-		$criteria = $this->em->createSimpleCriteria(Article::getClass(),['id'=> $id]);
-		return $criteria->toQuery()->fetchSingle();
+//		$criteria = $this->em->createSimpleCriteria(Article::getClass(),['id'=> $id]);
+//		return $criteria->toQuery()->fetchSingle();
 	}
 	
 	function saveArticle(Article $article) {
@@ -71,9 +72,16 @@ class ArticleDao {
 	//	$this->pdo->prepare('SELECT...'),
 	//}
 
-	function BadRequestExceptionIfs(?ParamBody $body, ?int $articleId) { 
+	/**
+	 * @throws PageNotFoundException
+	 * @throws StatusException
+	 * @throws BadRequestException
+	 */
+	function badRequestExceptionIfs(?ParamBody $body, ?int $articleId): void {
 		$bodyData = $body->parseJson();
-		if ($_SERVER['REQUEST_METHOD'] === 'POST') {
+
+
+		if ($articleId === null) {
 			if($body->getValue() === "") {
 				throw new BadRequestException('Body cant be empty');
 			}
@@ -106,7 +114,7 @@ class ArticleDao {
 			if (strlen($bodyData['text']) > 12000){
 				throw new BadRequestException('Text is too long');
 			}
-		} else if ($_SERVER['REQUEST_METHOD'] === 'PUT') {
+		} else {
 			$article = $this->getArticleById($articleId);
 			if($article === null) {
 				throw new PageNotFoundException('Article not found');

+ 42 - 0
src-php/test/internship/controller/ArticleControllerTest.php

@@ -106,6 +106,9 @@ class ArticleControllerTest extends TestCase {
 
 	}
 
+	/**
+	 * @throws StatusException
+	 */
 	function testPostDoArticle() {
 		$response = TestEnv::http()->newRequest()
 				->post(['api', 'article'])
@@ -124,6 +127,9 @@ class ArticleControllerTest extends TestCase {
 		$this->assertEquals('sport', $articleStruct['categoryName']);
 	}
 
+	/**
+	 * @throws StatusException
+	 */
 	function testPostDoArticleExpectExceptionBecauseCategoryNotFound() {
 		$this->expectException(BadRequestException::class);
 		$this->expectExceptionMessage('The Category must be international, national or sport');
@@ -136,6 +142,24 @@ class ArticleControllerTest extends TestCase {
        			])
 				->exec();
 	}
+
+
+	/**
+	 * @throws StatusException
+	 */
+	function testPostDoArticleExpectExceptionBecauseTitleTooLong() {
+		$this->expectException(BadRequestException::class);
+		$this->expectExceptionMessage('Title is too long');
+		TestEnv::http()->newRequest()
+				->post(['api', 'article'])
+				->bodyJson([
+						'title' => str_repeat('t', 256),
+						'categoryName' => 'sport',
+						'text' => 'text1'
+				])
+				->exec();
+	}
+
 	function testPutDoArticle() {
 		$response = TestEnv::http()->newRequest()
 				->put(['api', 'article',$this->article1Id])
@@ -227,6 +251,24 @@ class ArticleControllerTest extends TestCase {
 
 	}
 
+	/**
+	 * @throws StatusException
+	 */
+	function testPutDoArticleExpectExceptionBecauseTitleTooLong() {
+		$this->expectException(BadRequestException::class);
+		$this->expectExceptionMessage('Title is too long');
+
+		$response = TestEnv::http()->newRequest()
+				->put(['api', 'article', $this->article1Id])
+				->bodyJson([
+						'title' => str_repeat('t', 256),
+						'categoryName' => 'sport',
+						'text' => 'text1'
+				])
+				->exec();
+	}
+
+
 	function testDeleteDoArticle() {
 		$response = TestEnv::http()->newRequest()
 			->delete(['api', 'article',$this->article1Id])

Některé soubory nejsou zobrazeny, neboť je v těchto rozdílových datech změněno mnoho souborů