Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access of the functions and fixtures load #60

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions src/ApiTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ public function tearDown()
parent::tearDown();
}

/**
* @return string
*/
protected static function getKernelClass()
{
if (isset($_SERVER['KERNEL_CLASS'])) {
Expand Down Expand Up @@ -264,7 +267,7 @@ protected function loadFixturesFromDirectory($source = '')
$this->assertSourceExists($source);

$finder = new Finder();
$finder->files()->name('*.yml')->in($source);
$finder->files()->name('*.yml')->in($source)->sortByName();

if (0 === $finder->count()) {
throw new \RuntimeException(sprintf('There is no files to load in folder %s', $source));
Expand Down Expand Up @@ -307,7 +310,7 @@ protected function loadFixturesFromFile($source)
*
* @return string
*/
private function getFixtureRealPath($source)
protected function getFixtureRealPath($source)
{
$baseDirectory = $this->getFixturesFolder();

Expand All @@ -317,7 +320,7 @@ private function getFixtureRealPath($source)
/**
* @param array $objects
*/
private function persistObjects(array $objects)
protected function persistObjects(array $objects)
{
foreach ($objects as $object) {
$this->entityManager->persist($object);
Expand All @@ -327,7 +330,7 @@ private function persistObjects(array $objects)
/**
* @return string
*/
private function getFixturesFolder()
protected function getFixturesFolder()
{
if (null === $this->dataFixturesPath) {
$this->dataFixturesPath = (isset($_SERVER['FIXTURES_DIR'])) ? $this->getRootDir().$_SERVER['FIXTURES_DIR'] : $this->getCalledClassFolder().'/../DataFixtures/ORM';
Expand All @@ -339,7 +342,7 @@ private function getFixturesFolder()
/**
* @return string
*/
private function getExpectedResponsesFolder()
protected function getExpectedResponsesFolder()
{
if (null === $this->expectedResponsesPath) {
$this->expectedResponsesPath = (isset($_SERVER['EXPECTED_RESPONSE_DIR'])) ? $this->getRootDir().$_SERVER['EXPECTED_RESPONSE_DIR'] : $this->getCalledClassFolder().'/../Responses/Expected';
Expand All @@ -351,7 +354,7 @@ private function getExpectedResponsesFolder()
/**
* @return string
*/
private function getMockedResponsesFolder()
protected function getMockedResponsesFolder()
{
if (null === $this->mockedResponsesPath) {
$this->mockedResponsesPath = (isset($_SERVER['MOCKED_RESPONSE_DIR'])) ? $this->getRootDir().$_SERVER['MOCKED_RESPONSE_DIR'] : $this->getCalledClassFolder().'/../Responses/Mocked';
Expand All @@ -363,7 +366,7 @@ private function getMockedResponsesFolder()
/**
* @return string
*/
private function getCalledClassFolder()
protected function getCalledClassFolder()
{
$calledClass = get_called_class();
$calledClassFolder = dirname((new \ReflectionClass($calledClass))->getFileName());
Expand All @@ -375,8 +378,10 @@ private function getCalledClassFolder()

/**
* @param string $source
*
* @throws \RuntimeException
*/
private function assertSourceExists($source)
protected function assertSourceExists($source)
{
if (!file_exists($source)) {
throw new \RuntimeException(sprintf('File %s does not exist', $source));
Expand All @@ -386,7 +391,7 @@ private function assertSourceExists($source)
/**
* @return string
*/
private function getRootDir()
protected function getRootDir()
{
return $this->get('kernel')->getRootDir();
}
Expand Down
6 changes: 3 additions & 3 deletions src/JsonApiTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ protected function assertResponse(Response $response, $filename, $statusCode = 2
/**
* @param Response $response
*/
private function assertJsonHeader(Response $response)
protected function assertJsonHeader(Response $response)
{
parent::assertHeader($response, MediaTypes::JSON);
}
Expand All @@ -67,7 +67,7 @@ private function assertJsonHeader(Response $response)
*
* @throws \Exception
*/
private function assertJsonResponseContent(Response $response, $filename)
protected function assertJsonResponseContent(Response $response, $filename)
{
parent::assertResponseContent($this->prettifyJson($response->getContent()), $filename, 'json');
}
Expand All @@ -77,7 +77,7 @@ private function assertJsonResponseContent(Response $response, $filename)
*
* @return string
*/
private function prettifyJson($content)
protected function prettifyJson($content)
{
return json_encode(json_decode($content), JSON_PRETTY_PRINT);
}
Expand Down
6 changes: 3 additions & 3 deletions src/XmlApiTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ protected function assertResponse(Response $response, $filename, $statusCode = 2
/**
* @param Response $response
*/
private function assertXmlHeader(Response $response)
protected function assertXmlHeader(Response $response)
{
parent::assertHeader($response, MediaTypes::XML);
}
Expand All @@ -61,7 +61,7 @@ private function assertXmlHeader(Response $response)
*
* @throws \Exception
*/
private function assertXmlResponseContent(Response $actualResponse, $filename)
protected function assertXmlResponseContent(Response $actualResponse, $filename)
{
parent::assertResponseContent($this->prettifyXml($actualResponse->getContent()), $filename, 'xml');
}
Expand All @@ -71,7 +71,7 @@ private function assertXmlResponseContent(Response $actualResponse, $filename)
*
* @return string
*/
private function prettifyXml($actualResponse)
protected function prettifyXml($actualResponse)
{
$domXmlDocument = new \DOMDocument('1.0');
$domXmlDocument->preserveWhiteSpace = false;
Expand Down