Add more ApiFormat format tests
authoraddshore <addshorewiki@gmail.com>
Wed, 23 Oct 2013 15:10:02 +0000 (16:10 +0100)
committeraddshore <addshorewiki@gmail.com>
Thu, 24 Oct 2013 18:07:05 +0000 (19:07 +0100)
Adds tests for Json and wddx formats
Add @covers tags
Fixes some comments
Fixes scope

Change-Id: I5f22097ddcaeb917f856ba7aa0cb793caa17925e

tests/phpunit/includes/api/format/ApiFormatJsonTest.php [new file with mode: 0644]
tests/phpunit/includes/api/format/ApiFormatPhpTest.php
tests/phpunit/includes/api/format/ApiFormatTestBase.php
tests/phpunit/includes/api/format/ApiFormatWddxTest.php [new file with mode: 0644]

diff --git a/tests/phpunit/includes/api/format/ApiFormatJsonTest.php b/tests/phpunit/includes/api/format/ApiFormatJsonTest.php
new file mode 100644 (file)
index 0000000..c71faec
--- /dev/null
@@ -0,0 +1,17 @@
+<?php
+
+/**
+ * @group API
+ * @group Database
+ * @group medium
+ * @covers ApiFormatJson
+ */
+class ApiFormatJsonTest extends ApiFormatTestBase {
+
+       public function testValidSyntax( ) {
+               $data = $this->apiRequest( 'json', array( 'action' => 'query', 'meta' => 'siteinfo' ) );
+
+               $this->assertInternalType( 'array', json_decode( $data, true ) );
+               $this->assertGreaterThan( 0, count( (array)$data ) );
+       }
+}
index a0bbb2d..759dfc7 100644 (file)
@@ -4,11 +4,11 @@
  * @group API
  * @group Database
  * @group medium
+ * @covers ApiFormatPhp
  */
 class ApiFormatPhpTest extends ApiFormatTestBase {
 
-       public function testValidPhpSyntax() {
-
+       public function testValidyntax( ) {
                $data = $this->apiRequest( 'php', array( 'action' => 'query', 'meta' => 'siteinfo' ) );
 
                $this->assertInternalType( 'array', unserialize( $data ) );
index 153f2cf..24d8cb8 100644 (file)
@@ -1,9 +1,18 @@
 <?php
 
 abstract class ApiFormatTestBase extends ApiTestCase {
+
+       /**
+        * @param string $format
+        * @param array $params
+        * @param $data
+        *
+        * @return string
+        */
        protected function apiRequest( $format, $params, $data = null ) {
                $data = parent::doApiRequest( $params, $data, true );
 
+               /** @var ApiMain $module */
                $module = $data[3];
 
                $printer = $module->createPrinterByName( $format );
@@ -19,4 +28,5 @@ abstract class ApiFormatTestBase extends ApiTestCase {
 
                return $out;
        }
+
 }
diff --git a/tests/phpunit/includes/api/format/ApiFormatWddxTest.php b/tests/phpunit/includes/api/format/ApiFormatWddxTest.php
new file mode 100644 (file)
index 0000000..2cf6dca
--- /dev/null
@@ -0,0 +1,17 @@
+<?php
+
+/**
+ * @group API
+ * @group Database
+ * @group medium
+ * @covers ApiFormatWddx
+ */
+class ApiFormatWddxTest extends ApiFormatTestBase {
+
+       public function testValidSyntax( ) {
+               $data = $this->apiRequest( 'wddx', array( 'action' => 'query', 'meta' => 'siteinfo' ) );
+
+               $this->assertInternalType( 'array', wddx_deserialize( $data ) );
+               $this->assertGreaterThan( 0, count( (array)$data ) );
+       }
+}