Skip to content

Commit

Permalink
Added PHP unit test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
HancilSequeira committed Mar 29, 2020
1 parent e5bc6dd commit 5b39a6b
Show file tree
Hide file tree
Showing 15 changed files with 300 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,9 @@
/var/
/vendor/
###< symfony/framework-bundle ###

###> symfony/phpunit-bridge ###
.phpunit
.phpunit.result.cache
/phpunit.xml
###< symfony/phpunit-bridge ###
1 change: 1 addition & 0 deletions .idea/php.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/soccerManagementScore.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"symfony/http-client": "4.4.*",
"symfony/maker-bundle": "^1.14",
"symfony/orm-pack": "^1.0",
"symfony/phpunit-bridge": "^5.0",
"symfony/security-bundle": "4.4.*",
"symfony/serializer": "4.4.*",
"symfony/serializer-pack": "^1.0",
Expand Down
67 changes: 66 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file modified config/packages/fos_rest.yaml
100644 → 100755
Empty file.
Empty file modified config/routing/team.xml
100644 → 100755
Empty file.
Empty file modified src/Authorization/UserAuthorization.php
100644 → 100755
Empty file.
Empty file modified src/Controller/TeamController.php
100644 → 100755
Empty file.
Empty file modified src/Service/TeamService.php
100644 → 100755
Empty file.
Empty file modified src/Service/UtilityService.php
100644 → 100755
Empty file.
Empty file modified src/constant/CustomResponseConstant.php
100644 → 100755
Empty file.
15 changes: 15 additions & 0 deletions symfony.lock
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,21 @@
"symfony/orm-pack": {
"version": "v1.0.8"
},
"symfony/phpunit-bridge": {
"version": "4.3",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "master",
"version": "4.3",
"ref": "6d0e35f749d5f4bfe1f011762875275cd3f9874f"
},
"files": [
".env.test",
"bin/phpunit",
"phpunit.xml.dist",
"tests/bootstrap.php"
]
},
"symfony/polyfill-intl-icu": {
"version": "v1.15.0"
},
Expand Down
104 changes: 104 additions & 0 deletions tests/PlayerControllerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?php

namespace App\Tests;

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class PlayerControllerTest extends WebTestCase
{
protected function getBaseURL() {
return 'http://soccerManagement.local';
}

public function testPlayer()
{
$client = new \GuzzleHttp\Client([
'base_url' => $this->getBaseURL(),
'defaults' => [
'exceptions' => false
]
]);

$data = array(
"firstName"=> "Hancil q",
"lastName" => "Sequeira",
"playerImageURI"=>"http:://abc.jpeg"
);

$response = $client->get('/api/player', [
'body' => json_encode($data)
]);

$this->assertEquals(200, $response->getStatusCode());
$finishedData = json_decode($response->getBody(true), true);
}

public function testPutPlayer()
{
$client = new \GuzzleHttp\Client([
'base_url' => $this->getBaseURL(),
'defaults' => [
'exceptions' => false
]
]);

$data = array(
"firstName"=> "Hancil q",
"lastName" => "Sequeira",
"playerImageURI"=>"http:://abc.jpeg"
);

$response = $client->get('/api/player?id=3', [
'body' => json_encode($data)
]);

$this->assertEquals(200, $response->getStatusCode());
$finishedData = json_decode($response->getBody(true), true);
}

public function testDeletePlayer()
{
$client = new \GuzzleHttp\Client([
'base_url' => $this->getBaseURL(),
'defaults' => [
'exceptions' => false
]
]);


$response = $client->get('/api/player?playerId=3');

$this->assertEquals(200, $response->getStatusCode());
$finishedData = json_decode($response->getBody(true), true);
}

public function testPlayerById()
{
$client = new \GuzzleHttp\Client([
'base_url' => $this->getBaseURL(),
'defaults' => [
'exceptions' => false
]
]);

$response = $client->get('/api/player/3');

$this->assertEquals(200, $response->getStatusCode());
$finishedData = json_decode($response->getBody(true), true);
}

public function testPlayerListBasedOnIdOrNameAction()
{
$client = new \GuzzleHttp\Client([
'base_url' => $this->getBaseURL(),
'defaults' => [
'exceptions' => false
]
]);

$response = $client->get('/api/players/2');

$this->assertEquals(200, $response->getStatusCode());
$finishedData = json_decode($response->getBody(true), true);
}
}
106 changes: 106 additions & 0 deletions tests/TeamControllerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?php

namespace App\Tests;

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class TeamControllerTest extends WebTestCase
{
protected function getBaseURL() {
return 'http://soccerManagement.local';
}

public function testCreateTeam()
{
$client = new \GuzzleHttp\Client([
'base_url' => $this->getBaseURL(),
'defaults' => [
'exceptions' => false
]
]);

$data = array(
"name"=>"test",
"logoURI=">"http:://abc.jpeg"
);

$response = $client->get('/api/team',['body' => json_encode($data)]);

$this->assertEquals(200, $response->getStatusCode());
$finishedData = json_decode($response->getBody(true), true);
}

public function testPutTeam()
{
$client = new \GuzzleHttp\Client([
'base_url' => $this->getBaseURL(),
'defaults' => [
'exceptions' => false
]
]);

$data = array(
"name"=>"test",
"logoURI=">"http:://abc.jpeg"
);

$response = $client->get('/api/team?id=3', [
'body' => json_encode($data)
]);

$this->assertEquals(200, $response->getStatusCode());
$finishedData = json_decode($response->getBody(true), true);
}

public function testAddPlayerToTeam()
{
$client = new \GuzzleHttp\Client([
'base_url' => $this->getBaseURL(),
'defaults' => [
'exceptions' => false
]
]);

$data = array(
"teamId"=>1,
"playerId"=>3
);

$response = $client->get('/api/team-players', [
'body' => json_encode($data)
]);

$this->assertEquals(200, $response->getStatusCode());
$finishedData = json_decode($response->getBody(true), true);
}

public function testTeamListAction()
{
$client = new \GuzzleHttp\Client([
'base_url' => $this->getBaseURL(),
'defaults' => [
'exceptions' => false
]
]);

$response = $client->get('/api/players');

$this->assertEquals(200, $response->getStatusCode());
$finishedData = json_decode($response->getBody(true), true);
}

public function testPlayerListBasedOnTeamAction()
{
$client = new \GuzzleHttp\Client([
'base_url' => $this->getBaseURL(),
'defaults' => [
'exceptions' => false
]
]);

$response = $client->get('/api/players/2');

$this->assertEquals(200, $response->getStatusCode());
$finishedData = json_decode($response->getBody(true), true);
}
}

0 comments on commit 5b39a6b

Please sign in to comment.