Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

132
Views
PHPUnit 6.1.x arroja un error array_merge() cuando mi clase de prueba usa su propio método constructor

me sale este error:

 1) XTest::testX array_merge(): Argument #1 is not an array ERRORS! Tests: 1, Assertions: 0, Errors: 1.

En este caso de prueba:

 use PHPUnit\Framework\TestCase; class XTest extends TestCase { function __construct() {} function testX() { $this->assertTrue(true); } }

Si elimino el método __construct , mis pruebas pasan. ¿Qué está pasando con el manejo de PHPUnit de mis métodos constructores de clases? Funcionó bien en PHPUnit versión 4.8, pero ahora estoy usando PHPUnit versión 6.1.3

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

PHPUnit usa el constructor para inicializar el TestCase base

Puede ver el método constructor aquí: https://github.com/sebastianbergmann/phpunit/blob/6.1.3/src/Framework/TestCase.php#L328

 public function __construct($name = null, array $data = [], $dataName = '')

No debe usar el constructor, porque lo usa phpunit y cualquier cambio en la firma, etc. puede romper las cosas.

Puede usar los métodos especiales setUp y setUpBeforeClass que phpunit llamará por usted.

 use PHPUnit\Framework\TestCase; class XTest extends TestCase { function static setUpBeforeClass() { // Called once just like normal constructor // You can create database connections here etc } function setUp() { //Initialize the test case //Called for every defined test } function testX() { $this->assertTrue(true); } // Clean up the test case, called for every defined test public function tearDown() { } // Clean up the whole test class public static function tearDownAfterClass() { } }

Los documentos: https://phpunit.de/manual/current/en/fixtures.html

Tenga en cuenta que se llama al setUp para cada prueba especificada en la clase.

Para una única inicialización, puede usar setUpBeforeClass .

Y otro consejo: ejecute su phpunit con el indicador -v para mostrar los rastros de la pila;)

over 4 years ago · Santiago Trujillo Report

0

Como señaló correctamente la respuesta de Sander Visser, el constructor principal puede tener parámetros adicionales, etc., y generalmente querrá usar setUpBeforeClass o setUp , pero, si sabe lo que está haciendo, puede llamar a parent::__construct(); en el constructor de tu clase Test:

 public function __construct() { parent::__construct(); // Your construct here }

Editar 2019

En Codeception, esto también puede deberse a una sangría YML no válida en el archivo de su suite.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!