Jump to content

rick645

Members
  • Posts

    107
  • Joined

  • Last visited

Everything posted by rick645

  1. I had a look but I didn't really understand how to use it https://github.com/gmrchk/cli-testing-library#usage You need to create a file of this type import { prepareEnvironment } from '@gmrchk/cli-testing-library'; describe('My CLI', () => { it('program runs successfully', async () => { const { execute, cleanup } = await prepareEnvironment(); const { code } = await execute( 'node', './my-cli.js --help' ); expect(code).toBe(0); await cleanup(); }); }); and then where should we save it? Since they are tools written in JS (if I'm not mistaken), do the tests have to be launched from the browser? PS Do you know anything about this topic? https://forums.phpfreaks.com/topic/317297-vscode-docblock-and-tag-see/#comment-1612101 No one has responded yet....
  2. UPPPPPPPPPPPP
  3. UPPPPPPPPPPPPPPPPPPPPPPPPPPP
  4. PHP Intelephense extension installed. Cursor positioned in line 4, column 15. Press Ctrl+Shift+P, type "go to definition", and it appears "Non è stata trovata alcuna definizione…" (No definition has been found ...) https://pasteboard.co/7kEtT0JyS8Sk.png Why?
  5. As we know, to perform the unit tests in general is used phpunit https://phpunit.de/ But for functional tests? For example, let's consider the following script + cat bin/example-script #!/usr/bin/php <?php require "src/App.php"; /** * @return string Application output. */ function main(): string { $app = new App; // --- BEGIN CONFIG --- $app->setProperty1( // ... ); $app->setProperty2( // ... ); $app->setProperty3( // ... ); // --- END CONFIG --- $output = $app->run(); # RETURN: "Helo world!!!" return $output; } echo main() . PHP_EOL; # ECHO: "Helo world!!!" . PHP_EOL exit(123); # EXIT CODE: 123 We highlight some lines + grep '# ' bin/example-script $output = $app->run(); # RETURN: "Helo world!!!" echo main() . PHP_EOL; # ECHO: "Helo world!!!" . PHP_EOL exit(123); # EXIT CODE: 123 Request 1 I want to test that the output is the desired one: "Helo world!!!" . PHP_EOL Request 2 I want to test that the exit code is the desired one: 123 How can it be done? Is there a recommended practice?
  6. Redundant? mmmhhh... } catch (InvalidArgumentException&Err $throwable) { Catches exceptions that extend InvalidArgumentException and implement Err. Very comfortable, I would say!!! Wouldn't it be right to propose it for a future version of php?
  7. $ php -v | grep cli PHP 8.1.2-1ubuntu2.14 (cli) (built: Aug 18 2023 11:41:11) (NTS) $ cat catch.php <?php interface Err { function getExitCode(); } function main(Throwable&Err $throwable1) { #ID1 try { throw $throwable1; } catch (Throwable&Err $throwable2) { #ID2 echo $throwable2->getExitCode() . PHP_EOL; } } $throwable = new class extends Exception implements Err { function getExitCode() { return 123; } }; main($throwable); I highlight a few lines $ grep ID catch.php function main(Throwable&Err $throwable1) { #ID1 } catch (Throwable&Err $throwable2) { #ID2 So let's try $ php catch.php PHP Parse error: syntax error, unexpected token "&", expecting ")" in /tmp/catch.php on line 10 Why? mmmhhh... I try to remove Throwable& from the line #ID2 $ grep ID2 catch.php } catch (Err $throwable2) { #ID2 $ php catch.php 123 Works!!! So it seems that catch doesn't accept the type intersection. Why? Is there any official documentation that talks about it?
  8. $ cat main.php <?php require_once 'vendor/autoload.php'; $parser = new Console_CommandLine; $parser->addOption('verbose', [ 'short_name' => '-v', 'long_name' => '--verbose', 'action' => 'Counter', ]); $result = $parser->parse(); var_dump($result->options['verbose']); $ php main.php -vv --verbose int(3) $ php main.php NULL Very good!!! Thanks ;)
  9. ```` $ cat composer.json { "require": { "pear/console_commandline": "^1.2" } } $ cat main.php <?php require_once 'vendor/autoload.php'; $parser = new Console_CommandLine; $parser->addOption('verbose', array( 'multiple' => true, 'short_name' => '-v', 'long_name' => '--verbose', 'action' => 'StoreTrue', )); try { $result = $parser->parse(); print_r($result->options); } catch (Exception $exc) { $parser->displayError($exc->getMessage()); } $ php main.php -v | grep verbose [verbose] => 1 ```` OK, but... ```` $ php main.php -vvv | grep verbose [verbose] => 1 ```` I would have expected (third level verbosity) ```` [verbose] => 3 ```` Can you do something to solve?
  10. Just click on the icon at the bottom left. https://pasteboard.co/GcHNBkZXmi5N.png Sorry.
  11. I decided to install Wscode. I also installed the "PHP Intelephense" plugin. But I don't see the functionality I want. As described at the beginning, if for example they place the cursor (with the keyboard, not with the mouse) on a non -defined variable, I do not see the error appear anywhere. Only if I place myself with the mouse a sort of popups with the error. It may be good but that's not exactly what I want.
  12. Real. But what I like about eclipse is that it can be installed and above all updated through the official ubuntu packagers. Without periodically doing manual things like for phpstorm (which doesn't work for me anymore), netbeans, etc.
  13. What should I install exactly? No error/warning of any kind, unfortunately.
  14. Netbeans, for example, in the lower part of the window, displays the errors. To notice Variable $xyz seems to be unused in its scope Eclpse, on the other hand, does not do it. Don't you think it's a comfortable and useful thing? Could it therefore be configured in the same way as Netbeans? Or is there any plugin?
  15. I have expired the trial, and I should buy it. Have you purchased it (do you use landscape deceased)?
  16. RSYNC OUTPUT... rsync -n ... it shouldn't produce output, I apologize
  17. tmp.FdTgUEMZjh$ cat rsync-map-path #!/bin/bash rsync -n "$1" "$(./map-path "$1")" tmp.FdTgUEMZjh$ cat map-path #!/usr/bin/php <?php $paths = [ 'bin' => "remote:/bin", 'lib' => "remote:/lib", 'config' => "remote:/etc", 'config2' => "remote:/config", //... ]; echo $paths[$argv[1]]; tmp.FdTgUEMZjh$ ./rsync-map-path lib RSYNC OUTPUT...
  18. ... ... You are taking for granted that he is writing a web app. I thought you knew that, with php, can be write both web apps and cli apps
  19. First of all $ php -v PHP 8.1.2-1ubuntu2.13 (cli) (built: Jun 28 2023 14:01:49) (NTS) Copyright (c) The PHP Group Zend Engine v4.1.2, Copyright (c) Zend Technologies with Zend OPcache v8.1.2-1ubuntu2.13, Copyright (c), by Zend Technologies https://akrabat.com/turn-warnings-into-an-exception/ Interestingly, in PHP7, we can expect to see exceptions in the engine itself which should allow us to solve this problem like this: try { $result = file_get_contents($url); } catch (EngineException $e) { // do something with $e } Let's try... try { file_get_contents("http://x.y.z"); } catch (EngineException $e) { echo get_class($throwable) . ": CATCHED" . PHP_EOL; } Output PHP Warning: file_get_contents(): php_network_getaddresses: getaddrinfo for x.y.z failed: Temporary failure in name resolution PHP Warning: file_get_contents(http://x.y.z): Failed to open stream: php_network_getaddresses: getaddrinfo for x.y.z failed: Temporary failure in name resolution It seems that catching doesn't work. It appears that the line inside the catch block is not executed. Why?
  20. Programmers yes. End users don't: they should have as simple an interface as possible, which hides unnecessary details. websiite?
  21. however, the end user should not be asked to specify the extension as well
×
×
  • 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.