<commit_before><?php

namespace Nastoletni\Code\Slim;

use Nastoletni\Code\Slim\DecoratingCallableResolver;
use Nastoletni\Code\UserInterface\Controller\AbstractController;
use Nastoletni\Code\UserInterface\Controller\ControllerDecorator;
use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
use Psr\Container\NotFoundExceptionInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Slim\Interfaces\RouterInterface;
use Slim\Views\Twig;

class DecoratingCallableResolverTest extends TestCase
{
    public function testResolveWithChildOfAbstractControllerWithMethodInContainer()
    {
        $container = $this->getContainerWithClassMethod();
        /** @var AbstractController $controller */
        $controller = $container->get('controller');

        $controllerDecorator = $this->createMock(ControllerDecorator::class);
        $controllerDecorator
            ->expects($this->once())
            ->method('decorate');

        $decoratingCallableResolver = new DecoratingCallableResolver(
            $container,
            $controllerDecorator
        );

        $resolved = $decoratingCallableResolver->resolve('controller:home');
        $this->assertEquals($controller, $resolved[0]);
        $this->assertEquals('home', $resolved[1]);
    }

    public function testResolveWithInvokableChildOfAbstractControllerInContainer()
    {
        $container = $this->getContainerWithInvokableClass();
        /** @var AbstractController $controller */
        $controller = $container->get('controller');

        $controllerDecorator = $this->createMock(ControllerDecorator::class);
        $controllerDecorator
            ->expects($this->once())
            ->method('decorate');

        $decoratingCallableResolver = new DecoratingCallableResolver(
            $container,
            $controllerDecorator
        );

        $resolved = $decoratingCallableResolver->resolve('controller');
        $this->assertEquals($controller, $resolved[0]);
        $this->assertEquals('__invoke', $resolved[1]);
    }

    public function testResolveWithChildOfAbstractControllerWithMethod()
    {
        // FIXME: DRY, look at getContainerWithClassMethod()
        $controller = new class extends AbstractController {
            public function home(
                ServerRequestInterface $request,
                ResponseInterface $response
            ) {
                return $response;
            }
        };

        $controllerDecorator = $this->createMock(ControllerDecorator::class);
        $controllerDecorator
            ->expects($this->once())
            ->method('decorate');

        $decoratingCallableResolver = new DecoratingCallableResolver(
            $this->createMock(ContainerInterface::class),
            $controllerDecorator
        );

        $resolved = $decoratingCallableResolver->resolve([$controller, 'home']);<commit_msg>Delete FIXME from DecoratingCallableResolver test<commit_after><?php

namespace Nastoletni\Code\Slim;

use Nastoletni\Code\Slim\DecoratingCallableResolver;
use Nastoletni\Code\UserInterface\Controller\AbstractController;
use Nastoletni\Code\UserInterface\Controller\ControllerDecorator;
use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
use Psr\Container\NotFoundExceptionInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Slim\Interfaces\RouterInterface;
use Slim\Views\Twig;

class DecoratingCallableResolverTest extends TestCase
{
    public function testResolveWithChildOfAbstractControllerWithMethodInContainer()
    {
        $container = $this->getContainerWithClassMethod();
        /** @var AbstractController $controller */
        $controller = $container->get('controller');

        $controllerDecorator = $this->createMock(ControllerDecorator::class);
        $controllerDecorator
            ->expects($this->once())
            ->method('decorate');

        $decoratingCallableResolver = new DecoratingCallableResolver(
            $container,
            $controllerDecorator
        );

        $resolved = $decoratingCallableResolver->resolve('controller:home');
        $this->assertEquals($controller, $resolved[0]);
        $this->assertEquals('home', $resolved[1]);
    }

    public function testResolveWithInvokableChildOfAbstractControllerInContainer()
    {
        $container = $this->getContainerWithInvokableClass();
        /** @var AbstractController $controller */
        $controller = $container->get('controller');

        $controllerDecorator = $this->createMock(ControllerDecorator::class);
        $controllerDecorator
            ->expects($this->once())
            ->method('decorate');

        $decoratingCallableResolver = new DecoratingCallableResolver(
            $container,
            $controllerDecorator
        );

        $resolved = $decoratingCallableResolver->resolve('controller');
        $this->assertEquals($controller, $resolved[0]);
        $this->assertEquals('__invoke', $resolved[1]);
    }

    public function testResolveWithChildOfAbstractControllerWithMethod()
    {
        $controller = new class extends AbstractController {
            public function home(
                ServerRequestInterface $request,
                ResponseInterface $response
            ) {
                return $response;
            }
        };

        $controllerDecorator = $this->createMock(ControllerDecorator::class);
        $controllerDecorator
            ->expects($this->once())
            ->method('decorate');

        $decoratingCallableResolver = new DecoratingCallableResolver(
            $this->createMock(ContainerInterface::class),
            $controllerDecorator
        );

        $resolved = $decoratingCallableResolver->resolve([$controller, 'home']);
{'fraction_non_alphanumeric': 0.10760667903525047, 'fraction_numerical': 0.0013493000505987519, 'mean_word_length': 3.226657163221668, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2358671', 'n_tokens_mistral': 1486, 'n_tokens_neox': 1475, 'n_words': 230}