Giter Club home page Giter Club logo

Comments (12)

ondrejmirtes avatar ondrejmirtes commented on August 22, 2024 4

Thanks to everyone who tested it, seems it works. After 0.9 is out, I plan to automate this, having phpstan-shim dev-master built after every successful Travis build of the main repo + testing in the build whether it still works.

from phpstan-shim.

fprochazka avatar fprochazka commented on August 22, 2024 1

Extensions are an open problem right now, we've talked about this with @ondrejmirtes already.

The phar has to include all the extensions (at least the official ones), to make sure they refer to the prefixed classes. But only the extensions - the extra dependencies, they should be part of your project already.

My compiler already handles this case, but Ondra released it without it for now - the 0.7 was a big release already as is.

from phpstan-shim.

ondrejmirtes avatar ondrejmirtes commented on August 22, 2024 1

I have good news! I just pushed a freshly compiled PHAR that should support installing along the extensions! So feel free to try it out: 5f02c1f

How I verified that it works:

{
	"minimum-stability": "dev",
	"prefer-stable": true,
	"require": {
		"phpstan/phpstan-shim":"^0.9",
		"phpstan/phpstan-phpunit":"^0.9"
	}
}

results in this install log (I excluded PHPUnit dependencies):

$ composer install
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 30 installs, 0 updates, 0 removals
  - Installing phpunit/phpunit (6.4.4): Loading from cache
  - Installing phpstan/phpstan-shim (dev-master 5f02c1f): Cloning 5f02c1fa2f from cache
  - Installing phpstan/phpstan-phpunit (dev-master 87f1be6): Cloning 87f1be64dc from cache

So no phpstan dependencies are installed directly because of the extension, because they are already met thanks to phpstan-shim and the replace key in its composer.json.

With this phpstan.neon:

includes:
	- vendor/phpstan/phpstan-phpunit/extension.neon
	- vendor/phpstan/phpstan-phpunit/rules.neon

parameters:
	autoload_files:
		- test.php

And this test.php:

<?php

class TestCase extends \PHPUnit\Framework\TestCase
{

	public function testFoo()
	{
		$mock = $this->createMock(Foo::class);
		$mock->doFoo();
	}

}

class Foo
{

}

Running:

vendor/bin/phpstan.phar analyse test.php -c phpstan.neon -l 7

Results in:

 ------ -----------------------------------------------------------------------------------
  Line   test.php
 ------ -----------------------------------------------------------------------------------
  9      Call to an undefined method Foo&PHPUnit_Framework_MockObject_MockObject::doFoo().
 ------ -----------------------------------------------------------------------------------

As you can see, the type Foo&PHPUnit_Framework_MockObject_MockObject means that the PHPUnit extension is installed and registered correctly!

I urge everyone in this conversation to test out latest phpstan-shim dev-master whether it works for their use cases as well!

from phpstan-shim.

jkuchar avatar jkuchar commented on August 22, 2024

realated: fprochazka/phpstan-compiler#1

from phpstan-shim.

JanJakes avatar JanJakes commented on August 22, 2024

@jiripudil Actually I think composer require phpstan/phpstan-shim phpstan/phpstan-nette can't work in any case simply because phpstan-shim only contains a phpstan.phar archive and when you use it (vendor/bin/phpstan.phar ...) you don't load vendor/autoload.php at all.

Also @fprochazka I tried to compile PHPStan with the extensions, but how do I activate them? I can't reference a vendor/phpstan/phpstan-nette/extension.neon which is in a PHAR archive, right?

from phpstan-shim.

hrach avatar hrach commented on August 22, 2024

@JanJakes this is needed: nette/di#153

from phpstan-shim.

ondrejmirtes avatar ondrejmirtes commented on August 22, 2024

from phpstan-shim.

fprochazka avatar fprochazka commented on August 22, 2024

@JanJakes

I can't reference a vendor/phpstan/phpstan-nette/extension.neon which is in a PHAR archive, right?

You can! Read the readme for 0.6.x: https://github.com/phpstan/phpstan-shim/tree/0.6.x#extensions

from phpstan-shim.

ondrejmirtes avatar ondrejmirtes commented on August 22, 2024

I replaced the provide section with replace and the result is much better. Although, the current problem with installing PHAR along the extensions is that the Dynamic*ReturnTypeExtension interface contains references to PhpParser nodes which are prefixed in the PHAR, rendering implementations incompatible with the interface.

I will probably try to turn off prefixing the PhpParser library which should help and the extensions should become usable.

from phpstan-shim.

fprochazka avatar fprochazka commented on August 22, 2024

FYI, the original compiler was meant to compile the PHAR with the extensions so you would only enable them, no additional installing.

from phpstan-shim.

ondrejmirtes avatar ondrejmirtes commented on August 22, 2024

from phpstan-shim.

vasekbrychta avatar vasekbrychta commented on August 22, 2024

I've tried it with phpstan-nette and seems working. Only phpstan-shim gets installed. Thanks!

from phpstan-shim.

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.