Szybkie posty

Jeżeli coś jest wartego uwagi a nie jest to materiał na pełnoprawnwgo posta na blogu to będę starać się to umieszczać w tym miejscu.

#ajax #apache #behat #bitbacket #bootstrap #composer #cookies #cqrs #css #css flex #ct8 #curl #docker #doctrine #edukacja #enet #enp sla #filmy #firma #funkcje php #git #google #htaccess #html #inne #javascript #jedzenie #jquery #js/jquery #kawały #krypto #laravel #linux #oop #pdo #php #php wzorce narzędzia #phpmyadmin #phpspec #phpstan #phpstorm #phpunit #podcast #rabbit #redis #seo #soap #sql #symfony #szukanie po stringach w php #twig #virtual host #visual studio code #vue #wamp #windows #wino-nalewki #wyrazenia regularne #wzorce projektowe #xml #xxx #zdjecia #złote myśli
  • Szukasz po tagu: phpspec
  • Ilość rekordów w bazie: 5

test commanda lub query cqrs

    private function clientLimitTest(
        PaymentLimiterDTO $paymentLimiterDTO,
        PaymentGroupInterface $paymentGroup,
        PaymentInterface $payment,
        AddressInterface $address,
        PaymentLimitDataValueObject $paymentLimitDataValueObject,
        OrderTotalAdapter $orderTotalAdapter,
        QueryBusInterface $queryBus,
        MoneyInterface $money,
        Cart $cart,
        int $orderTotalAmount,
        bool $expected
    ): void {
        //arrange
        $phone = '500500500';
        $address->getPhone()->willReturn($phone);
        $cart->getAccountAddress()->willReturn($address);
        $cart->getTotal()->willReturn($money);
        $money->getAmount()->willReturn($orderTotalAmount);
        $orderTotalAdapter->getTotalValue($orderTotalAmount)->willReturn($orderTotalAmount);
        $paymentLimiterDTO->getCart()->willReturn($cart);
        $payment = $payment->getWrappedObject();
        $paymentGroup->getFirstPaymentWithIntegration(PaymentIntegrationEnum::MOKKA)->willReturn($payment);
        $paymentLimiterDTO->getPaymentGroup()->willReturn($paymentGroup);
        $paymentLimitDataValueObject->clientIsActive()->willReturn(true);
        $paymentLimitDataValueObject->getClientLimitAmount()->willReturn('5666.00');
        $paymentLimitDataValueObject->getClientStatus()->willReturn(PaymentLimitApiCode::INACTIVE);
        $paymentLimitDataValueObject = $paymentLimitDataValueObject->getWrappedObject();
        $queryBus->handle(
            Argument::that(
                static function (PaymentLimitQueryMessage $message) use (
                    $phone,
                    $payment,
                    $paymentLimitDataValueObject
                ) {
                    $message->setPaymentLimitDataValueObject($paymentLimitDataValueObject);
                    return true;
                }
            )
        )->shouldBeCalledOnce();
        //act/assert
        $this->callOnWrappedObject('shouldExclude', [$paymentLimiterDTO])->shouldBeEqualTo($expected);
    }

test cache i prywatnej metody

    public function it_is_get_data_test(
        ServiceConflictsFinder $serviceConflictsFinder,
        CacheProviderInterface $cacheProvider
    ): void {
        $serviceId = 1;
        $serviceId2 = 2;

        $serviceConflictsFinder->getData($serviceId)->willReturn([2, 3])->shouldBeCalledOnce();
        $serviceConflictsFinder->getData($serviceId2)->willReturn([7, 8])->shouldBeCalledOnce();
        $cacheProvider->load(
            sprintf('service_conflict_data_%s', $serviceId),
            CacheLifetime::HOUR,
            Argument::that(
                function ($serviceId) {
                    call_user_func($serviceId);

                    return [2, 3];
                }
            )
        )->willReturn([2, 3])->shouldBeCalledOnce();
        $cacheProvider->load(
            sprintf('service_conflict_data_%s', $serviceId2),
            CacheLifetime::HOUR,
            Argument::that(
                function ($serviceId2) {
                    call_user_func($serviceId2);

                    return [7, 8];
                }
            )
        )->willReturn([7, 8])->shouldBeCalledOnce();

        $this->getDataOfConflictsServices([1, 2])->shouldBe([1 => [2, 3], 2 => [7, 8]]);
    }

php spec wprawdzenie czy metoda rzucza odpowiedni wyjątek

$this->shouldThrow(InvalidArgumentException::class)->during('vote', [$token, new Order(), ['xxx', 'yyy']]);

php spec test formularza

class FastOrderReturnCreatorSpec extends ObjectBehavior
{
    public function it_is_initializable(): void
    {
        $this->shouldHaveType(FastOrderReturnCreator::class);
        $this->shouldBeAnInstanceOf(OrderEditFormInterface::class);
    }

    public function let(
        FormFactoryInterface $formFactory,
        RouterInterface $router
    ): void {
        $this->beConstructedWith($formFactory, $router);
    }

    public function it_creates_form(
        FormFactoryInterface $formFactory,
        RouterInterface $router,
        OrderInterface $order,
        FormInterface $form
    ): void {
        $orderId = 1;
        $url = '/order/fast-order-return/1';

        $order->getId()->willReturn($orderId)->shouldBeCalledOnce();
        $router->generate('enp_enp0026_order_fast_return', ['orderId' => $orderId])->willReturn($url);

        $formFactory->createNamed(
            'order_return',
            FastOrderReturnType::class,
            null,
            [
                'action' => $url,
                'method' => Request::METHOD_PUT,
            ]
        )->willReturn($form);

        $this->createOrderEditForm($order)->shouldBe($form);
    }

php spec tets translatora w symfony

public function it_should_return_true(Order $order, TranslatorInterface $translator): void
    {
        $flagsToBlock = ['xxxx', 'aaaa', 'bbbb'];

        $order->hasFlagByCode('xxxx')->willReturn(false);
        $order->hasFlagByCode('aaaa')->willReturn(false);
        $order->hasFlagByCode('bbbb')->willReturn(false);

        $translator->trans(
            'enp.order.order_quick_return.order_source.error',
            [
                '%flagsToBlock%' => implode(',', $flagsToBlock),
            ],
            'EnpOrderBundle'
        )->willReturn('message');

        $this->beConstructedWith($flagsToBlock, $translator);
        $this->check($order)->shouldReturn(true);
        $this->getErrorMessage()->shouldBe('message');
    }