Skip to content

Commit

Permalink
Refactor endpoint tests so they are easier to implement
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack-Dane committed Jun 23, 2024
1 parent aaf3127 commit f0ab9b2
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 60 deletions.
23 changes: 6 additions & 17 deletions tests/end_to_end_tests/tests/endpoint_tests/CF7_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,20 @@

namespace end_to_end_tests\tests\endpoint_tests;

use PHPUnit\Framework\TestCase;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\ClientException;
require_once __DIR__ . '/EndpointTestBase.php';


class CF7_Test extends TestCase
class CF7_Test extends EndpointTestBase
{

public function setUp(): void
protected function endpoint()
{
$this->client = new Client();
return 'http://localhost:8000/?rest_route=/odoo_conn/v1/get-contact-7-forms';
}

public function test_get_odoo_forms()
public function test()
{
$failure = false;
try {
$this->client->request(
"GET", "http://localhost:8000/?rest_route=/odoo_conn/v1/get-contact-7-forms"
);
} catch (ClientException $e) {
$failure = true;
$this->assertEquals(401, $e->getResponse()->getStatusCode());
}
$this->assertTrue($failure);
$this->make_request();
}

}
36 changes: 36 additions & 0 deletions tests/end_to_end_tests/tests/endpoint_tests/EndpointTestBase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace end_to_end_tests\tests\endpoint_tests;

use PHPUnit\Framework\TestCase;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\ClientException;


abstract class EndpointTestBase extends Testcase {

public function setUp(): void
{
$this->client = new Client();
}

protected abstract function endpoint();

protected function make_request()
{
$failure = false;
try {
$this->client->request(
'GET', $this->endpoint()
);
} catch (ClientException $e) {
$failure = true;
$this->assertEquals(401, $e->getResponse()->getStatusCode());
}
$this->assertTrue($failure);
}

}


?>
34 changes: 12 additions & 22 deletions tests/end_to_end_tests/tests/endpoint_tests/OdooConnection_Test.php
Original file line number Diff line number Diff line change
@@ -1,31 +1,21 @@
<?php

use \PHPUnit\Framework\TestCase;
use \GuzzleHttp\Client;
use \GuzzleHttp\Exception\ClientException;
namespace end_to_end_tests\tests\endpoint_tests;

class OdooConnection_Test extends TestCase
{
require_once __DIR__ . '/EndpointTestBase.php';

public function setUp(): void
{
$this->client = new Client();
}
class OdooConnection_Test extends EndpointTestBase
{

public function test_get_odoo_connections()
{
$failure = false;
try {
$this->client->request(
"GET", "http://localhost:8000/?rest_route=/odoo_conn/v1/get-odoo-connections"
);
} catch (ClientException $e) {
$failure = true;
$this->assertEquals(401, $e->getResponse()->getStatusCode());
}
$this->assertTrue($failure);
}
protected function endpoint()
{
return 'http://localhost:8000/?rest_route=/odoo_conn/v1/get-odoo-connections';
}

public function test()
{
$this->make_request();
}
}

?>
33 changes: 12 additions & 21 deletions tests/end_to_end_tests/tests/endpoint_tests/OdooForm_Test.php
Original file line number Diff line number Diff line change
@@ -1,30 +1,21 @@
<?php

use PHPUnit\Framework\TestCase;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\ClientException;
namespace end_to_end_tests\tests\endpoint_tests;

class OdooForm_Test extends TestCase
require_once __DIR__ . '/EndpointTestBase.php';

class OdooForm_Test extends EndpointTestBase
{

public function setUp(): void
{
$this->client = new Client();
}
protected function endpoint()
{
return 'http://localhost:8000/?rest_route=/odoo_conn/v1/get-odoo-forms';
}

public function test_get_odoo_forms()
{
$failure = false;
try {
$this->client->request(
"GET", "http://localhost:8000/?rest_route=/odoo_conn/v1/get-odoo-forms"
);
} catch (ClientException $e) {
$failure = true;
$this->assertEquals(401, $e->getResponse()->getStatusCode());
}
$this->assertTrue($failure);
}
public function test()
{
$this->make_request();
}

}

Expand Down

0 comments on commit f0ab9b2

Please sign in to comment.