Giter Club home page Giter Club logo

Comments (6)

sebastianbergmann avatar sebastianbergmann commented on May 20, 2024

Thank you for your report.

Please provide a minimal, self-contained, reproducing test case that shows the problem you are reporting.

Without such a minimal, self-contained, reproducing test case I will not be able to investigate this issue.

from phpunit.

abodnar avatar abodnar commented on May 20, 2024

Example unit test:

<?php

namespace Tests\Unit;

use DateTime;
use PHPUnit\Framework\TestCase;

class PrefillDateArrayTest extends TestCase
{
//    private array $defaultArrayItem; <---since this commented out, it will cause the deprecation

    public function setUp(): void
    {
        $this->defaultArrayItem = [];
        parent::setUp();
    }

    public function test(): void
    {
        $from = new DateTime;
        $to = new DateTime('+1 month');

        for ($date = clone $from; $date < $to; $date->modify('+1 day')) {
            $this->defaultArrayItem[$date->format('Y-m-d')] = 1;
        }
        $this->assertIsArray($this->defaultArrayItem);
    }
}

from phpunit.

sebastianbergmann avatar sebastianbergmann commented on May 20, 2024

I cannot reproduce this:

$ tree -L 2
.
├── composer.json
├── composer.lock
├── phpunit.xml
├── tests
│   └── PrefillDateArrayTest.php
└── vendor
    ├── autoload.php
    ├── bin
    ├── composer
    ├── myclabs
    ├── nikic
    ├── phar-io
    ├── phpunit
    ├── sebastian
    └── theseer

11 directories, 5 files
$ cat composer.json                           
{
    "require-dev": {
        "phpunit/phpunit": "^10.5"
    }
}
$ cat phpunit.xml
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
         cacheDirectory=".phpunit.cache"
         colors="true">
    <testsuites>
        <testsuite name="default">
            <directory>tests</directory>
        </testsuite>
    </testsuites>
</phpunit>
$ ./vendor/bin/phpunit
PHPUnit 10.5.16 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.3.4
Configuration: /home/sb/5793/phpunit.xml

D                                                                   1 / 1 (100%)

Time: 00:00.012, Memory: 8.00 MB

OK, but there were issues!
Tests: 1, Assertions: 1, Deprecations: 1.
$ ./vendor/bin/phpunit --display-deprecations
PHPUnit 10.5.16 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.3.4
Configuration: /home/sb/5793/phpunit.xml

D                                                                   1 / 1 (100%)

Time: 00:00.008, Memory: 8.00 MB

1 test triggered 1 PHP deprecation:

1) /home/sb/5793/tests/PrefillDateArrayTest.php:14
Creation of dynamic property Tests\Unit\PrefillDateArrayTest::$defaultArrayItem is deprecated

Triggered by:

* Tests\Unit\PrefillDateArrayTest::test
  /home/sb/5793/tests/PrefillDateArrayTest.php:18

OK, but there were issues!
Tests: 1, Assertions: 1, Deprecations: 1.

The deprecation is correctly reported.

from phpunit.

abodnar avatar abodnar commented on May 20, 2024

Interesting. I don't know if it matters, but I am doing this with the Laravel sail 8.2 image and have also tried this with the php8.2-cli image. Is there a particular php.ini setting that might dictate if the deprecations are shown?

from phpunit.

sebastianbergmann avatar sebastianbergmann commented on May 20, 2024

Sure: error_reporting.

from phpunit.

abodnar avatar abodnar commented on May 20, 2024

Sigh...of course they have it set to E_ALL & ~E_DEPRECATED & ~E_STRICT in sail. But what's odd is I've added a <ini name="error_reporting" value="32767"/> to my phpunit.xml and also added ini_set('error_reporting', E_ALL); to a setUp method in my base TestCase class and still never displays any summary info about the deprecations.

At this point, it's clearly something with the configuration of Laravel/php/my code that is overriding what I expect to happen. So I appreciate you pointing me at what l needed to look at.

Thanks!

from phpunit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.