Jump to content

rick645

Members
  • Posts

    101
  • Joined

  • Last visited

Recent Profile Visitors

1,765 profile views

rick645's Achievements

Advanced Member

Advanced Member (4/5)

0

Reputation

  1. I agree XMLDiff is a class, and it works as a class should work IHMO <?xml version="1.0"?> <dm:diff xmlns:dm="http://www.locus.cz/diffmark"> <dm:delete> <aaa xxx1="aaa"/> </dm:delete> <dm:insert> <aaa xxx2="bbb"> </aaa> </dm:insert> </dm:diff> Of course, I would say yes
  2. Here's my scenario + ls -1 main.php x1.xml x2.xml + cat x1.xml <aaa xxx1="aaa"> <bbb> blabla1 </bbb> </aaa> + cat x2.xml <aaa xxx2="bbb"> </aaa> + cat main.php <?php $x1Doc = new DOMDocument(); $x1Doc->load('x1.xml'); $x2Doc = new DOMDocument(); $x2Doc->load('x2.xml'); $dom = new XMLDiff\DOM; $diff = $dom->diff($x1Doc, $x2Doc); echo $dom->merge($x1Doc, $diff)->saveXML(); Let's do some tests + php main.php <?xml version="1.0"?> <aaa xxx2="bbb"> </aaa> I was expecting something like this though <aaa xxx1="aaa" xxx2="bbb"> <bbb> blabla1 </bbb> </aaa> Any suggestions?
  3. $ cat Dockerfile FROM php:8.2 RUN apt-get update \ && apt-get -y install php8.2-xml $ docker build . [+] Building 6.7s (5/5) FINISHED docker:default => [internal] load build definition from Dockerfile 0.0s => => transferring dockerfile: 109B 0.0s => [internal] load metadata for docker.io/library/php:8.2 0.0s => [internal] load .dockerignore 0.0s => => transferring context: 2B 0.0s => CACHED [1/2] FROM docker.io/library/php:8.2 0.0s => ERROR [2/2] RUN apt-get update && apt-get -y install php8.2-xml 6.5s ------ > [2/2] RUN apt-get update && apt-get -y install php8.2-xml: 0.349 Get:1 http://deb.debian.org/debian bookworm InRelease [151 kB] 0.477 Get:2 http://deb.debian.org/debian bookworm-updates InRelease [55.4 kB] 0.533 Get:3 http://deb.debian.org/debian-security bookworm-security InRelease [47.9 kB] 0.585 Get:4 http://deb.debian.org/debian bookworm/main amd64 Packages [8792 kB] 4.158 Get:5 http://deb.debian.org/debian bookworm-updates/main amd64 Packages [13.5 kB] 4.168 Get:6 http://deb.debian.org/debian-security bookworm-security/main amd64 Packages [241 kB] 5.182 Fetched 9301 kB in 5s (1881 kB/s) 5.182 Reading package lists... 5.746 Reading package lists... 6.326 Building dependency tree... 6.472 Reading state information... 6.480 Package php8.2-xml is not available, but is referred to by another package. 6.480 This may mean that the package is missing, has been obsoleted, or 6.480 is only available from another source 6.480 6.484 E: Package 'php8.2-xml' has no installation candidate ------ Dockerfile:2 -------------------- 1 | FROM php:8.2 2 | >>> RUN apt-get update \ 3 | >>> && apt-get -y install php8.2-xml 4 | -------------------- ERROR: failed to solve: process "/bin/sh -c apt-get update && apt-get -y install php8.2-xml" did not complete successfully: exit code: 100 Why?
  4. Ok, but, details aside, do you have any solution?
  5. $ docker login -u blabla... Password: WARNING! Your password will be stored unencrypted in /home/rino/.docker/config.json. Configure a credential helper to remove this warning. See https://docs.docker.com/engine/reference/commandline/login/#credential-stores Login Succeeded $ docker build . RUN apt-get update \ && apt-get -y install php-xml blabla... 7.782 E: Package 'php-xml' has no installation candidate More precisely? More precisely?
  6. + /usr/bin/docker run --rm php:8.2 \ php -r "echo XMLDiff\File::merge();" Fatal error: Uncaught Error: Class "XMLDiff\File" not found in Command line code:1 mmmhhh... Perhaps the appropriate extension must be installed (it should be php8.2-xml). So let's do this + cat Dockerfile FROM php:8.2 RUN apt-get update \ && apt-get -y install php8.2-xml \ && docker-php-ext-install php8.2-xml \ && docker-php-ext-enable php8.2-xml + /usr/bin/docker build -t test . [+] Building 7.4s (5/5) FINISHED docker:default => [internal] load build definition from Dockerfile 0.0s => => transferring dockerfile: 196B 0.0s => [internal] load metadata for docker.io/library/php:8.2 0.0s => [internal] load .dockerignore 0.0s => => transferring context: 2B 0.0s => CACHED [1/2] FROM docker.io/library/php:8.2 0.0s => ERROR [2/2] RUN apt-get update && apt-get -y install php8.2-xml && docker-php-ext-install php8.2-xml 7.3s ------ > [2/2] RUN apt-get update && apt-get -y install php8.2-xml && docker-php-ext-install php8.2-xml && docker-php-ext-enable php8.2-xml: 0.342 Get:1 http://deb.debian.org/debianbookworm InRelease [151 kB] 0.469 Get:2 http://deb.debian.org/debianbookworm-updates InRelease [55.4 kB] 0.539 Get:3 http://deb.debian.org/debian-securitybookworm-security InRelease [48.0 kB] 0.597 Get:4 http://deb.debian.org/debianbookworm/main amd64 Packages [8792 kB] 4.851 Get:5 http://deb.debian.org/debianbookworm-updates/main amd64 Packages [13.5 kB] 4.861 Get:6 http://deb.debian.org/debian-securitybookworm-security/main amd64 Packages [241 kB] 5.883 Fetched 9301 kB in 6s (1653 kB/s) 5.883 Reading package lists... 6.445 Reading package lists... 7.019 Building dependency tree... 7.167 Reading state information... 7.175 Package php8.2-xml is not available, but is referred to by another package. 7.175 This may mean that the package is missing, has been obsoleted, or 7.175 is only available from another source 7.175 7.179 E: Package 'php8.2-xml' has no installation candidate ------ Dockerfile:3 -------------------- 2 | 3 | >>> RUN apt-get update \ 4 | >>> && apt-get -y install php8.2-xml \ 5 | >>> && docker-php-ext-install php8.2-xml \ 6 | >>> && docker-php-ext-enable php8.2-xml 7 | -------------------- ERROR: failed to solve: process "/bin/sh -c apt-get update && apt-get -y install php8.2-xml && docker-php-ext-install php8.2-xml && docker-php-ext-enable php8.2-xml" did not complete successfully: exit code: 100 Why? Obviously, consequently + /usr/bin/docker run test \ php -r "echo XMLDiff\File::merge();" Unable to find image 'test:latest' locally docker: Error response from daemon: pull access denied for test, repository does not exist or may require 'docker login': denied: requested access to the resource is denied. So, how do you install the php8.2-xml extension?
  7. Of course, to keep the global namespace in order, it would be preferable to encapsulate everything in a function main(), front_controller(), etc., and call it.
  8. Nor is it convenient to always return all the output in the end, and then print it all in one fell swoop. Often, in fact, as already mentioned, it is a good thing to have intermediate outputs (avoiding embarrassing mute scenes), to understand what the software is doing running (also respecting the time sequence) fwrite($outputStream, “Downloading...\n”); // do something fwrite($outputStream, “Unpacking...\n”); // do something fwrite($outputStream, “Install...\n”); // do something What do you think?
  9. $ cat MyTest.php <?php declare(strict_types=1); use PHPUnit\Framework\TestCase; final class MyTest extends TestCase { final public function testMy(): void { var_dump($this); $this->setOutputCallback(); $this->getActualOutput(); } } $ vendor/bin/phpunit MyTest.php PHPUnit 11.2.0 by Sebastian Bergmann and contributors. Runtime: PHP 8.3.6 object(MyTest)#307 (41) { ["backupGlobals":"PHPUnit\Framework\TestCase":private]=> bool(false) ["backupGlobalsExcludeList":"PHPUnit\Framework\TestCase":private]=> array(0) { } ["backupStaticProperties":"PHPUnit\Framework\TestCase":private]=> bool(false) ["backupStaticPropertiesExcludeList":"PHPUnit\Framework\TestCase":private]=> array(0) { } ["snapshot":"PHPUnit\Framework\TestCase":private]=> NULL ["backupGlobalErrorHandlers":"PHPUnit\Framework\TestCase":private]=> array(1) { [0]=> object(PHPUnit\Runner\ErrorHandler)#220 (6) { ["baseline":"PHPUnit\Runner\ErrorHandler":private]=> NULL ["enabled":"PHPUnit\Runner\ErrorHandler":private]=> bool(true) ["originalErrorReportingLevel":"PHPUnit\Runner\ErrorHandler":private]=> int(32767) ["source":"PHPUnit\Runner\ErrorHandler":private]=> object(PHPUnit\TextUI\Configuration\Source)#64 (20) { ["baseline":"PHPUnit\TextUI\Configuration\Source":private]=> NULL ["ignoreBaseline":"PHPUnit\TextUI\Configuration\Source":private]=> bool(false) ["includeDirectories":"PHPUnit\TextUI\Configuration\Source":private]=> object(PHPUnit\TextUI\Configuration\FilterDirectoryCollection)#66 (1) { ["directories":"PHPUnit\TextUI\Configuration\FilterDirectoryCollection":private]=> array(0) { } } ["includeFiles":"PHPUnit\TextUI\Configuration\Source":private]=> object(PHPUnit\TextUI\Configuration\FileCollection)#39 (1) { ["files":"PHPUnit\TextUI\Configuration\FileCollection":private]=> array(0) { } } ["excludeDirectories":"PHPUnit\TextUI\Configuration\Source":private]=> object(PHPUnit\TextUI\Configuration\FilterDirectoryCollection)#40 (1) { ["directories":"PHPUnit\TextUI\Configuration\FilterDirectoryCollection":private]=> array(0) { } } ["excludeFiles":"PHPUnit\TextUI\Configuration\Source":private]=> object(PHPUnit\TextUI\Configuration\FileCollection)#41 (1) { ["files":"PHPUnit\TextUI\Configuration\FileCollection":private]=> array(0) { } } ["restrictDeprecations":"PHPUnit\TextUI\Configuration\Source":private]=> bool(false) ["restrictNotices":"PHPUnit\TextUI\Configuration\Source":private]=> bool(false) ["restrictWarnings":"PHPUnit\TextUI\Configuration\Source":private]=> bool(false) ["ignoreSuppressionOfDeprecations":"PHPUnit\TextUI\Configuration\Source":private]=> bool(false) ["ignoreSuppressionOfPhpDeprecations":"PHPUnit\TextUI\Configuration\Source":private]=> bool(false) ["ignoreSuppressionOfErrors":"PHPUnit\TextUI\Configuration\Source":private]=> bool(false) ["ignoreSuppressionOfNotices":"PHPUnit\TextUI\Configuration\Source":private]=> bool(false) ["ignoreSuppressionOfPhpNotices":"PHPUnit\TextUI\Configuration\Source":private]=> bool(false) ["ignoreSuppressionOfWarnings":"PHPUnit\TextUI\Configuration\Source":private]=> bool(false) ["ignoreSuppressionOfPhpWarnings":"PHPUnit\TextUI\Configuration\Source":private]=> bool(false) ["ignoreSelfDeprecations":"PHPUnit\TextUI\Configuration\Source":private]=> bool(false) ["ignoreDirectDeprecations":"PHPUnit\TextUI\Configuration\Source":private]=> bool(false) ["ignoreIndirectDeprecations":"PHPUnit\TextUI\Configuration\Source":private]=> bool(false) ["deprecationTriggers":"PHPUnit\TextUI\Configuration\Source":private]=> array(2) { ["functions"]=> array(0) { } ["methods"]=> array(0) { } } } ["sourceFilter":"PHPUnit\Runner\ErrorHandler":private]=> object(PHPUnit\TextUI\Configuration\SourceFilter)#219 (0) { } ["deprecationTriggers":"PHPUnit\Runner\ErrorHandler":private]=> array(2) { ["functions"]=> array(0) { } ["methods"]=> array(0) { } } } } ["backupGlobalExceptionHandlers":"PHPUnit\Framework\TestCase":private]=> array(0) { } ["runClassInSeparateProcess":"PHPUnit\Framework\TestCase":private]=> NULL ["runTestInSeparateProcess":"PHPUnit\Framework\TestCase":private]=> NULL ["preserveGlobalState":"PHPUnit\Framework\TestCase":private]=> bool(false) ["inIsolation":"PHPUnit\Framework\TestCase":private]=> bool(false) ["expectedException":"PHPUnit\Framework\TestCase":private]=> NULL ["expectedExceptionMessage":"PHPUnit\Framework\TestCase":private]=> NULL ["expectedExceptionMessageRegExp":"PHPUnit\Framework\TestCase":private]=> NULL ["expectedExceptionCode":"PHPUnit\Framework\TestCase":private]=> NULL ["providedTests":"PHPUnit\Framework\TestCase":private]=> array(1) { [0]=> object(PHPUnit\Framework\ExecutionOrderDependency)#302 (4) { ["className":"PHPUnit\Framework\ExecutionOrderDependency":private]=> string(6) "MyTest" ["methodName":"PHPUnit\Framework\ExecutionOrderDependency":private]=> string(6) "testMy" ["shallowClone":"PHPUnit\Framework\ExecutionOrderDependency":private]=> bool(false) ["deepClone":"PHPUnit\Framework\ExecutionOrderDependency":private]=> bool(false) } } ["data":"PHPUnit\Framework\TestCase":private]=> array(0) { } ["dataName":"PHPUnit\Framework\TestCase":private]=> string(0) "" ["methodName":"PHPUnit\Framework\TestCase":private]=> string(6) "testMy" ["groups":"PHPUnit\Framework\TestCase":private]=> array(1) { [0]=> string(7) "default" } ["dependencies":"PHPUnit\Framework\TestCase":private]=> array(0) { } ["dependencyInput":"PHPUnit\Framework\TestCase":private]=> array(0) { } ["iniSettings":"PHPUnit\Framework\TestCase":private]=> array(0) { } ["locale":"PHPUnit\Framework\TestCase":private]=> array(0) { } ["mockObjects":"PHPUnit\Framework\TestCase":private]=> array(0) { } ["status":"PHPUnit\Framework\TestCase":private]=> object(PHPUnit\Framework\TestStatus\Unknown)#298 (1) { ["message":"PHPUnit\Framework\TestStatus\TestStatus":private]=> string(0) "" } ["numberOfAssertionsPerformed":"PHPUnit\Framework\TestCase":private]=> int(0) ["testResult":"PHPUnit\Framework\TestCase":private]=> NULL ["output":"PHPUnit\Framework\TestCase":private]=> string(0) "" ["outputExpectedRegex":"PHPUnit\Framework\TestCase":private]=> NULL ["outputExpectedString":"PHPUnit\Framework\TestCase":private]=> NULL ["outputBufferingActive":"PHPUnit\Framework\TestCase":private]=> bool(true) ["outputBufferingLevel":"PHPUnit\Framework\TestCase":private]=> int(1) ["outputRetrievedForAssertion":"PHPUnit\Framework\TestCase":private]=> bool(false) ["doesNotPerformAssertions":"PHPUnit\Framework\TestCase":private]=> bool(false) ["customComparators":"PHPUnit\Framework\TestCase":private]=> array(0) { } ["testValueObjectForEvents":"PHPUnit\Framework\TestCase":private]=> object(PHPUnit\Event\Code\TestMethod)#81 (7) { ["file":"PHPUnit\Event\Code\Test":private]=> string(15) "/app/MyTest.php" ["className":"PHPUnit\Event\Code\TestMethod":private]=> string(6) "MyTest" ["methodName":"PHPUnit\Event\Code\TestMethod":private]=> string(6) "testMy" ["line":"PHPUnit\Event\Code\TestMethod":private]=> int(8) ["testDox":"PHPUnit\Event\Code\TestMethod":private]=> object(PHPUnit\Event\Code\TestDox)#293 (3) { ["prettifiedClassName":"PHPUnit\Event\Code\TestDox":private]=> string(2) "My" ["prettifiedMethodName":"PHPUnit\Event\Code\TestDox":private]=> string(2) "My" ["prettifiedAndColorizedMethodName":"PHPUnit\Event\Code\TestDox":private]=> string(2) "My" } ["metadata":"PHPUnit\Event\Code\TestMethod":private]=> object(PHPUnit\Metadata\MetadataCollection)#297 (1) { ["metadata":"PHPUnit\Metadata\MetadataCollection":private]=> array(0) { } } ["testData":"PHPUnit\Event\Code\TestMethod":private]=> object(PHPUnit\Event\TestData\TestDataCollection)#292 (2) { ["data":"PHPUnit\Event\TestData\TestDataCollection":private]=> array(0) { } ["fromDataProvider":"PHPUnit\Event\TestData\TestDataCollection":private]=> NULL } } ["wasPrepared":"PHPUnit\Framework\TestCase":private]=> bool(true) ["failureTypes":"PHPUnit\Framework\TestCase":private]=> array(0) { } ["expectedUserDeprecationMessage":"PHPUnit\Framework\TestCase":private]=> array(0) { } ["expectedUserDeprecationMessageRegularExpression":"PHPUnit\Framework\TestCase":private]=> array(0) { } } E 1 / 1 (100%) Time: 00:00.006, Memory: 6.00 MB There was 1 error: 1) MyTest::testMy Error: Call to undefined method MyTest::setOutputCallback() /app/MyTest.php:10 ERRORS! Tests: 1, Assertions: 0, Errors: 1.
  10. OK!!! Allow me another question. https://www.w3resource.com/php/PHPUnit/writing-tests-for-phpunit-outputs.php methods setOutputCallback() and getActualOutput() are mentioned here, but they don't work for me Error: Call to undefined method PHPUnit\Framework\TestCase::setOutputCallback() Error: Call to undefined method PHPUnit\Framework\TestCase::getActualOutput() Why?
  11. https://docs.phpunit.de/en/11.1/writing-tests-for-phpunit.html#writing-tests-for-phpunit-output-examples-outputtest-php But it gives me an error //PHPUnit 11.1.3 by Sebastian Bergmann and contributors. //Runtime: PHP 8.3.6 //this->expectedOutputString() Error: Call to undefined method OutputTest::expectedOutputString() //parent::expectedOutputString() Error: Call to undefined method PHPUnit\Framework\TestCase::expectedOutputString() Why?
  12. Many say that is not recommended to print (text, data, info...) in a function/method, because it makes it difficult to test (unless inelegant stratagems are used). Here's a demonstration $ cat FileTest.php <?php function copyFileExample($echoOutput) { $verboseText = "Copying file... please wait...\n"; if ($echoOutput) echo $verboseText; /* * since it is an example, instead of copy(), * the sleep(5) function is used, to simulate copying a file, * which let's pretend it takes 5 seconds */ sleep(5); // replaces copy() function if (!$echoOutput) return $verboseText; } class FileTest extends PHPUnit\Framework\TestCase { static function copyProvider() { return [ [ "echoOutput" => true // not recommended [HIGHLIGHT] ], [ "echoOutput" => false // recommended [HIGHLIGHT] ], ]; } /** * @dataProvider copyProvider */ function testCopy($echoOutput) { $this->assertEquals( "Copying file... please wait...\n", copyFileExample($echoOutput) ); } } I highlight some parts $ grep HIGHLIGHT FileTest.php "echoOutput" => true // not recommended [HIGHLIGHT] "echoOutput" => false // recommended [HIGHLIGHT] So let's launch the tests $ phpunit FileTest.php PHPUnit 10.5.20 by Sebastian Bergmann and contributors. Runtime: PHP 8.1.2-1ubuntu2.17 Copying file... please wait... F. 2 / 2 (100%) There was 1 failure: 1) FileTest::testCopy with data set #0 (true) Failed asserting that null matches expected 'Copying file... please wait...\n '. FileTest.php:37 FAILURES! Tests: 2, Assertions: 2, Failures: 1. As you can see, one of the two tests fails (the one in which true is given for the parameter), for the reason above. For the other test, however, nothing is reported, so it means that it's fine, but... but... but... all of this hides an irregularity. I don't know if I'll be able to explain it.... In practice, if you run copyFileExample(echoOutput: true); // BAD PRACTICE (difficult to test output), BUT GOOD RESULT "Copying file... please wait..." is displayed the process stops for 5 seconds (pretending to copy some file) the process ends normally Instead if you execute echo copyFileExample(echoOutput: false); // GOOD PRACTICE, BUT... the process stops (hangs) for 5 seconds: it seems to have frozen, no output... but then suddenly it says "Copying file... please wait..."; when in reality the waiting is already over (there is nothing left to wait for): the time sequence is not respected So is there a way to reconcile the two?
  13. For certain needs I want to use it; for others not. Instead of uninstalling and reinstalling it, I wanted to know if there is a way to turn it off, or rather, among those I proposed, which is the most correct one (or if both are equivalent). Nothing more, nothing lessexit!!!
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.