Comments (6)
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.
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.
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.
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.
Sure: error_reporting
.
from phpunit.
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)
- Reduce output of Constraint failure descriptions, when asserting against trivial data types
- `assertObjectNotEquals()` HOT 3
- Duplicate CI pipeline jobs HOT 2
- TestCase::createStubForIntersectionOfInterfaces returns a Stub without an expects() method, triggering an exception when calling ->method() HOT 3
- Calling `method()` on a test stub created using `createStubForIntersectionOfInterfaces()` throws an unexpected exception HOT 3
- Run code coverage without a phpunit.xml HOT 6
- [Question] returnCallback + willReturnOnConsecutiveCalls HOT 2
- Avoid abstract test warning HOT 3
- Too few arguments to function PHPUnit\Framework\TestCase::__construct(), 0 passed HOT 5
- Depends attribute and annotation only skip tests, but don't execute them on success HOT 2
- Test with dependencies and data provider fails HOT 3
- Testing a method in a Custom Extension class HOT 5
- Is it possible to remove final declaration HOT 2
- [DX] Massive deprecations when upgrading to 10.5.18 and 10.5.20 HOT 4
- Arbitrary annotations attached to test cases. HOT 2
- advice on installing phpunit HOT 1
- Unknown option "--ansi" HOT 1
- Allow attributes for code coverage targeting to also be used on the test method level (instead of only on the test class level) HOT 4
- Allow enabling process isolation on suite/test base class HOT 1
- Include deprecation/warning failures in JUnit logs
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from phpunit.