mirror of
				https://github.com/kevinveenbirkenbach/infinito.git
				synced 2025-11-03 18:58:01 +00:00 
			
		
		
		
	Optimized for SPA
This commit is contained in:
		
							
								
								
									
										0
									
								
								application/symfony/tests/Integration/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								application/symfony/tests/Integration/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,41 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace Tests\Integration\Controller;
 | 
			
		||||
 | 
			
		||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
 | 
			
		||||
use Symfony\Component\HttpFoundation\Request;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 */
 | 
			
		||||
class RoutesGetStatusIntegrationTest extends KernelTestCase
 | 
			
		||||
{
 | 
			
		||||
    const GET_URLS_STATUS = [
 | 
			
		||||
        'login' => 200,
 | 
			
		||||
        'imprint' => 200,
 | 
			
		||||
        'register' => 301,
 | 
			
		||||
        'logout' => 302,
 | 
			
		||||
        'profile/edit' => 302,
 | 
			
		||||
        'spa' => 200,
 | 
			
		||||
    ];
 | 
			
		||||
 | 
			
		||||
    public function setUp(): void
 | 
			
		||||
    {
 | 
			
		||||
        self::bootKernel();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testParameterlesGetUrls(): void
 | 
			
		||||
    {
 | 
			
		||||
        foreach (self::GET_URLS_STATUS as $url => $status) {
 | 
			
		||||
            $this->parameterlesGetRouteTest($url, $status);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private function parameterlesGetRouteTest(string $url, int $status): void
 | 
			
		||||
    {
 | 
			
		||||
        $request = new Request([], [], [], [], [], ['REQUEST_URI' => $url, null]);
 | 
			
		||||
        $request->setMethod(Request::METHOD_GET);
 | 
			
		||||
        $response = static::$kernel->handle($request);
 | 
			
		||||
        $this->assertEquals($status, $response->getStatusCode());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,78 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace Tests\Integration\Controller;
 | 
			
		||||
 | 
			
		||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
 | 
			
		||||
use App\DBAL\Types\LanguageType;
 | 
			
		||||
use App\DBAL\Types\Meta\Right\LayerType;
 | 
			
		||||
use App\DBAL\Types\RESTResponseType;
 | 
			
		||||
use Symfony\Component\HttpFoundation\Request;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 *
 | 
			
		||||
 * @todo Implement more tests for success etc.
 | 
			
		||||
 */
 | 
			
		||||
class RoutesReachableIntegrationTest extends KernelTestCase
 | 
			
		||||
{
 | 
			
		||||
    public function setUp(): void
 | 
			
		||||
    {
 | 
			
		||||
        self::bootKernel();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testAllRoutePossibilities()
 | 
			
		||||
    {
 | 
			
		||||
        foreach (LayerType::getChoices() as $layer => $layerDescription) {
 | 
			
		||||
            $this->controller($layer);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private function controller(string $entity)
 | 
			
		||||
    {
 | 
			
		||||
        $this->language($entity, Request::METHOD_GET);
 | 
			
		||||
        $this->language($entity, Request::METHOD_POST);
 | 
			
		||||
        $this->language($entity.'s', Request::METHOD_GET);
 | 
			
		||||
        $this->slugAndId($entity, Request::METHOD_PUT);
 | 
			
		||||
        $this->slugAndId($entity, Request::METHOD_GET);
 | 
			
		||||
        $this->slugAndId($entity, Request::METHOD_DELETE);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private function slugAndId(string $route, string $method): void
 | 
			
		||||
    {
 | 
			
		||||
        $this->language("$route/12345", $method);
 | 
			
		||||
        $this->language("$route/asdfg", $method);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @todo Implement routing without i18l part!
 | 
			
		||||
     *
 | 
			
		||||
     * @param string $entity
 | 
			
		||||
     * @param string $method
 | 
			
		||||
     */
 | 
			
		||||
    private function language(string $entity, string $method): void
 | 
			
		||||
    {
 | 
			
		||||
        //$this->type('api/'.$entity, $method);
 | 
			
		||||
        foreach (LanguageType::getChoices() as $language) {
 | 
			
		||||
            $this->type("$language/api/$entity", $method);
 | 
			
		||||
            $this->type("$language/html/$entity", $method);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private function type(string $route, string $method): void
 | 
			
		||||
    {
 | 
			
		||||
        $this->routeAssert($route, $method);
 | 
			
		||||
        foreach (RESTResponseType::getChoices() as $restResponseType => $value) {
 | 
			
		||||
            $this->routeAssert("$route.$restResponseType", $method);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private function routeAssert(string $url, string $method): void
 | 
			
		||||
    {
 | 
			
		||||
        $request = new Request([], [], [], [], [], [
 | 
			
		||||
            'REQUEST_URI' => $url,
 | 
			
		||||
        ]);
 | 
			
		||||
        $request->setMethod($method);
 | 
			
		||||
        $response = static::$kernel->handle($request);
 | 
			
		||||
        $this->assertNotEquals(404, $response->getStatusCode(), "Route $url with Method $method sends an 404 response!");
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,37 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace Tests\Integration\DataFixtures;
 | 
			
		||||
 | 
			
		||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
 | 
			
		||||
use Doctrine\ORM\EntityManager;
 | 
			
		||||
use App\Entity\Source\AbstractSource;
 | 
			
		||||
use App\DBAL\Types\SystemSlugType;
 | 
			
		||||
use App\Entity\Source\Complex\UserSourceInterface;
 | 
			
		||||
 | 
			
		||||
class SourceFixturesIntegrationTest extends KernelTestCase
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * @var EntityManager
 | 
			
		||||
     */
 | 
			
		||||
    protected $entityManager;
 | 
			
		||||
 | 
			
		||||
    public function setUp(): void
 | 
			
		||||
    {
 | 
			
		||||
        self::bootKernel();
 | 
			
		||||
        $this->entityManager = static::$kernel->getContainer()->get('doctrine')->getManager();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testImpressumSource(): void
 | 
			
		||||
    {
 | 
			
		||||
        $sourceRepository = $this->entityManager->getRepository(AbstractSource::class);
 | 
			
		||||
        $imprint = $sourceRepository->findOneBySlug(SystemSlugType::IMPRINT);
 | 
			
		||||
        $this->assertInternalType('string', $imprint->getText());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGuestUserSource(): void
 | 
			
		||||
    {
 | 
			
		||||
        $sourceRepository = $this->entityManager->getRepository(AbstractSource::class);
 | 
			
		||||
        $userSource = $sourceRepository->findOneBySlug(SystemSlugType::GUEST_USER);
 | 
			
		||||
        $this->assertInstanceOf(UserSourceInterface::class, $userSource);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,50 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace Tests\Integration\Domain\SourceManagement;
 | 
			
		||||
 | 
			
		||||
use PHPUnit\Framework\TestCase;
 | 
			
		||||
use App\Entity\Source\SourceInterface;
 | 
			
		||||
use App\Domain\SourceManagement\SourceMemberManagerInterface;
 | 
			
		||||
use App\Domain\SourceManagement\SourceMemberManager;
 | 
			
		||||
use App\Domain\SourceManagement\SourceMemberInformation;
 | 
			
		||||
use App\Domain\SourceManagement\SourceMembershipInformation;
 | 
			
		||||
use App\Entity\Source\PureSource;
 | 
			
		||||
 | 
			
		||||
class SourceMemberManagerIntegrationTest extends TestCase
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * @var SourceInterface
 | 
			
		||||
     */
 | 
			
		||||
    private $source;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @var SourceMemberManagerInterface
 | 
			
		||||
     */
 | 
			
		||||
    private $sourceMemberManager;
 | 
			
		||||
 | 
			
		||||
    public function setUp(): void
 | 
			
		||||
    {
 | 
			
		||||
        $this->source = new PureSource();
 | 
			
		||||
        $this->sourceMemberManager = new SourceMemberManager($this->source);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testSourceMemberInformationIntegration(): void
 | 
			
		||||
    {
 | 
			
		||||
        $childSource = new PureSource();
 | 
			
		||||
        $sourceMemberInformation = new SourceMemberInformation($this->source);
 | 
			
		||||
        $this->sourceMemberManager->addMember($childSource);
 | 
			
		||||
        $this->assertEquals($childSource, $sourceMemberInformation->getAllMembers()->get(0));
 | 
			
		||||
        $this->sourceMemberManager->removeMember($childSource);
 | 
			
		||||
        $this->assertEquals(0, $sourceMemberInformation->getAllMembers()->count());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testSourceMembershipInformationIntegration(): void
 | 
			
		||||
    {
 | 
			
		||||
        $parentSource = new PureSource();
 | 
			
		||||
        $sourceMemberInformation = new SourceMembershipInformation($this->source);
 | 
			
		||||
        $this->sourceMemberManager->addMembership($parentSource);
 | 
			
		||||
        $this->assertEquals($parentSource, $sourceMemberInformation->getAllMemberships()->get(0));
 | 
			
		||||
        $this->sourceMemberManager->removeMembership($parentSource);
 | 
			
		||||
        $this->assertEquals(0, $sourceMemberInformation->getAllMemberships()->count());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,49 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace Integration\Entity\Source;
 | 
			
		||||
 | 
			
		||||
use Doctrine\ORM\EntityManagerInterface;
 | 
			
		||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
 | 
			
		||||
use App\Repository\Source\SourceRepository;
 | 
			
		||||
use App\Entity\Source\PureSourceInterface;
 | 
			
		||||
use App\Entity\Source\PureSource;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 */
 | 
			
		||||
class PureSourceIntegrationTest extends KernelTestCase
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * @var EntityManagerInterface
 | 
			
		||||
     */
 | 
			
		||||
    private $entityManager;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @var SourceRepository
 | 
			
		||||
     */
 | 
			
		||||
    private $sourceRepository;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @var PureSourceInterface
 | 
			
		||||
     */
 | 
			
		||||
    private $pureSource;
 | 
			
		||||
 | 
			
		||||
    public function setUp(): void
 | 
			
		||||
    {
 | 
			
		||||
        self::bootKernel();
 | 
			
		||||
        $this->entityManager = self::$container->get('doctrine.orm.default_entity_manager');
 | 
			
		||||
        $this->sourceRepository = $this->entityManager->getRepository(PureSource::class);
 | 
			
		||||
        $this->pureSource = new PureSource();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testDatabaseProcess(): void
 | 
			
		||||
    {
 | 
			
		||||
        $this->entityManager->persist($this->pureSource);
 | 
			
		||||
        $this->entityManager->flush();
 | 
			
		||||
        $this->assertGreaterThan(0, $this->pureSource->getId());
 | 
			
		||||
        $this->entityManager->remove($this->pureSource);
 | 
			
		||||
        $this->entityManager->flush();
 | 
			
		||||
        $this->expectException(\TypeError::class);
 | 
			
		||||
        $this->pureSource->getId();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,66 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace Tests\Integration;
 | 
			
		||||
 | 
			
		||||
use PHPUnit\Framework\TestCase;
 | 
			
		||||
use Doctrine\Common\Collections\ArrayCollection;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * This class tests if all needed Depencies for a source are implemented!
 | 
			
		||||
 *
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 */
 | 
			
		||||
class SourceIntegrationTest extends TestCase
 | 
			
		||||
{
 | 
			
		||||
    const SOURCE_DIRECTORY = __DIR__.'/../../src/Entity/Source';
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @var ArrayCollection
 | 
			
		||||
     */
 | 
			
		||||
    protected $sources;
 | 
			
		||||
 | 
			
		||||
    private function iterate(string $path)
 | 
			
		||||
    {
 | 
			
		||||
        $directoryIterator = new \DirectoryIterator($path);
 | 
			
		||||
        foreach ($directoryIterator as $fileInfo) {
 | 
			
		||||
            if (!in_array($fileInfo->getFilename(), [
 | 
			
		||||
                '.',
 | 
			
		||||
                '..',
 | 
			
		||||
            ])) {
 | 
			
		||||
                $pathname = $fileInfo->getPathname();
 | 
			
		||||
                if ($fileInfo->isDir()) {
 | 
			
		||||
                    $this->iterate($pathname);
 | 
			
		||||
                } elseif (false === strpos($pathname, 'Interface.php')) {
 | 
			
		||||
                    $this->sources->add(realpath($pathname));
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function setUp(): void
 | 
			
		||||
    {
 | 
			
		||||
        $this->sources = new ArrayCollection();
 | 
			
		||||
        $this->iterate(self::SOURCE_DIRECTORY);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private function filterSourcePath(string $path): string
 | 
			
		||||
    {
 | 
			
		||||
        $path = str_replace('/Abstract', '/', $path);
 | 
			
		||||
        $path = str_replace('.php', '', $path);
 | 
			
		||||
 | 
			
		||||
        return $path;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private function getInterfacePath(string $path): string
 | 
			
		||||
    {
 | 
			
		||||
        return $this->filterSourcePath($path).'Interface.php';
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testInterfaces(): void
 | 
			
		||||
    {
 | 
			
		||||
        foreach ($this->sources as $source) {
 | 
			
		||||
            $interfacePath = $this->getInterfacePath($source);
 | 
			
		||||
            $this->assertTrue(file_exists($this->getInterfacePath($source)), "Interface $interfacePath for $source doesn't exist!");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user