Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Function parameters initialized with a class constant throw an exception

Aperta
#118 2 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
30/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
php
Ambito
testing-qa

Direzione di ricerca

Inizia eseguendo tests/AspectMockTest.php con il bootstrap e l’esempio UserModel.php dell’issue. Traccia il fallimento attraverso BeforeMockTransformer.php e lo stack parser-reflection di goaop, in particolare NodeExpressionResolver e ReflectionEngine. Il lavoro è completato quando l’esempio testDouble viene eseguito senza l’eccezione del locator PDO, preservando il parametro predefinito con costante di classe.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Hello,

In the following code :

<?php
// test/bootstrap.php
require __DIR__ . '/../vendor/autoload.php'; // composer autoload
$kernel = \AspectMock\Kernel::getInstance();
$kernel->init([
        'debug' => true,
        'includePaths' => [
                __DIR__ . '/../src',
                'excludePaths' => [
                        __DIR__ . '/../tests'
                ]
        ]
]);
?>

<?php
// src/UserModel.php

namespace AM\Demo;

class UserModel {

     public function save()
     {
         return("Save is not mocking\n");
     }

     public function get($id, $type = \PDO::FETCH_ASSOC)
     {
     }

}
?>

<?php
// tests/AspectMockTest.php

use AspectMock\Test as test;
use AM\Demo\UserModel;

class AspectMockTest extends \PHPUnit_Framework_TestCase
{
        public function testDouble()
        {
           $mock = test::double('AM\Demo\UserModel', ['save' => "save is mocking"]);
        }

        protected function tearDown()
        {
          test::clean(); // remove all registered test doubles
        }
}

when we launch the test we get the following exception :

PHPUnit 5.7.3 by Sebastian Bergmann and contributors.


Starting test 'AspectMockTest::testDouble'.
E                                                                   1 / 1 (100%)

Time: 1.6 seconds, Memory: 24.75MB

There was 1 error:

1) AspectMockTest::testDouble
InvalidArgumentException: Class PDO was not found by locator

/testgo/vendor/goaop/parser-reflection/src/ReflectionEngine.php:112
/testgo/vendor/goaop/parser-reflection/src/ReflectionEngine.php:127
/testgo/vendor/goaop/parser-reflection/src/ReflectionClass.php:45
/testgo/vendor/goaop/parser-reflection/src/ValueResolver/NodeExpressionResolver.php:301
/testgo/vendor/goaop/parser-reflection/src/ValueResolver/NodeExpressionResolver.php:259
/testgo/vendor/goaop/parser-reflection/src/ValueResolver/NodeExpressionResolver.php:118
/testgo/vendor/goaop/parser-reflection/src/ValueResolver/NodeExpressionResolver.php:99
/testgo/vendor/goaop/parser-reflection/src/ReflectionParameter.php:99
/testgo/vendor/goaop/parser-reflection/src/Traits/ReflectionFunctionLikeTrait.php:164
/testgo/vendor/codeception/aspect-mock/src/AspectMock/Intercept/BeforeMockTransformer.php:56
/testgo/vendor/goaop/framework/src/Instrument/Transformer/CachingTransformer.php:124
/testgo/vendor/goaop/framework/src/Instrument/Transformer/CachingTransformer.php:83
/testgo/vendor/goaop/framework/src/Instrument/ClassLoading/SourceTransformingLoader.php:134
/testgo/vendor/goaop/framework/src/Instrument/ClassLoading/SourceTransformingLoader.php:101
/testgo/vendor/goaop/framework/src/Instrument/ClassLoading/AopComposerLoader.php:136
/testgo/vendor/goaop/framework/src/Instrument/ClassLoading/AopComposerLoader.php:136
/testgo/vendor/codeception/aspect-mock/src/AspectMock/Test.php:97
/testgo/tests/AspectMockOrmTest.php:53

ERRORS!
Tests: 1, Assertions: 0, Errors: 1.

Do you have any solution or fix to help us please ?

Lingua principale
PHP
Stelle
784
Fork
132
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Codeception/AspectMock

Tutte le issue di Codeception/AspectMock

Issue simili

Altre issue su PHP

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.