Neovim Intelephense

Updated: 03 November 2024

Notes to assist with config and use of the Intelephense PHP LSP:

Neovim LSP log file: ~/.local/state/nvim/lsp.log

https://intelephense.com/

Install on your system npm install -g intelephense but is probably installed by Mason anyway.

See here: ./.local/share/nvim/mason/packages/intelephense/node_modules/intelephense

The root of a PHP project is identified by a .git folder or a composer.json file.

nvim-lspconfig intelephense docs

https://github.com/bmewburn

Perhaps an alternative to Intelephense https://github.com/phpactor/phpactor

Intelephense and Intelephense docs on GitHub https://github.com/bmewburn

Buying a Licence makes most of the LSP warnings disappear!

Try running command :LspInfo

PHP in Docker

Updated: 17 May 2024

Pre-configured Docker images (including Xdebug) from Jetbrains https://github.com/JetBrains/phpstorm-docker-images


Run a php script

docker run -it --rm --name my-running-script \
-v "$PWD":/usr/src/myapp \
-w /usr/src/myapp \
php:7.4-cli php script.php

Run the php development server

docker run -it --rm --name php-server \
-v "$PWD":/usr/src/myapp \
-w /usr/src/myapp \
-p 8000:8000 \
php:8.2-cli php -S 0.0.0.0:8000

Prophecy

Updated: 17 September 2022

Dummy

$dummy = $this->prophesize(SomeClass::class);
$sut->action($dummy->reveal());

// with phpspec
class MarkdownSpec extends ObjectBehavior
{
    function it_converts_text_from_an_external_source(Reader $reader)
    {
        // $reader is a Dummy at this point because we've added
        // no behaviour nor made any assertions on its methods.
    }
}

Stub

$stub = $this->prophesize(SomeClass::class);
$stub->getSomething()->willReturn('foo');
$sut->action($stub->reveal());

// with phpspec
class MarkdownSpec extends ObjectBehavior
{
    function it_converts_text_from_an_external_source(Reader $reader)
    {
        $reader->getMarkdown()->willReturn("Hi, there");

        // $reader is now a Stub because we are controlling its behaviour.

        $this->toHtmlFromReader($reader)->shouldReturn("Hi, there");
    }
}

Mock

$mock = $this->prophesize(SomeClass::class);
$mock->doSomething('bar')->shouldBeCalled();
$sut->action($mock->reveal());

// with phpspec
class MarkdownSpec extends ObjectBehavior
{
    function it_outputs_converted_text(Writer $writer)
    {
        $writer->writeText("Hi, there")->shouldBeCalled();

        // Adding an assertion before the double is used makes it a Mock.

        $this->outputHtml("Hi, there", $writer);
    }
}

Spy

$spy = $this->prophesize(SomeClass::class);
$sut->action($spy->reveal());
$spy->doSomething('bar')->shouldHaveBeenCalled();

// with phpspec
class MarkdownSpec extends ObjectBehavior
{
    function it_outputs_converted_text(Writer $writer)
    {
        $this->outputHtml("Hi, there", $writer);

        // Adding an expectation after the double is used makes it a Spy.
        $writer->writeText("Hi, there")->shouldHaveBeenCalled();
    }
}