Giter Club home page Giter Club logo

phpstorm-quick-mock's People

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

phpstorm-quick-mock's Issues

Quick mock fails when using the new "public readonly" notation for Constructor Property Promotion

Describe the bug
In PHP8, constructor property promotion was introduced. On top of that we can now define visibility and immutability of a property.

Example:

public function __construct(
        private readonly EventLogInterface $eventLogService,
        private readonly FileUploadRepository $fileUploadRepository
) {
}

Quick mock will create these annotations:

/** @var private|ObjectProphecy */
private $eventLogService;
/** @var private|ObjectProphecy */
private $fileUploadRepository;

existing mocks are regenerated

regression of #18, introduced in #26

2 sources of the problem here:

  • ExistingMocks is currently always returning true, if not both properties (like $data and $dataQuickMocked) are present (in 95% of all cases) - logic needs to be rewritten to notMocked(existingField) && notMocked(existingSuffixedField)
  • val parameterMapByName = ArrayList<Pair<String, Parameter>>(parametersWithoutMocks.size) ignores allParameters, they should be combined in a real Map

Don't regenerate mocks/members if already present

Is your feature request related to a problem? Please describe.
When iterating over different version of the constructor (e.g. when doing TDD), the plugin will regenerate the mocks and members of the test.

Describe the solution you'd like
The plugin should identify previously generated mocks and members and not regenerate them.

Describe alternatives you've considered
If the plugin could reliably identify previously generated mocks as such, it could alternatively delete all previously generated mocks and regenerate them.

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Error type: Cannot find preset's package (github>whitesource/merge-confidence:beta)

context menu only showing up on cursor located between parentheses

The option for mock-generation only shows up in the context menu when the cursor is located between the parentheses. It would be nice if this option would be available when the cursor is located on the classname of the subject. Also i would reccomend to rename the context menu text to something like "Quick-Moc:k: add constructor prophecies"

Line break on too many constructor arguments

First: thanks for adding the feature "Adding missing constructor properties".

I have a little adjustment:
since we have a PHPMD rule that limits the lines to 140 characters, I'd like the plugin to handle this.
First approach: count the characters and add line breaks if it exceeds 140 characters.
Second approach: if the constructor has >= 4 Parameters, do line breaks.
Third Approach: do line breaks by default.

Example:

$this->subject = new Authenticator(
    $this->clientRegistry->reveal(),
    $this->router->reveal(),
    $this->proxyHandler->reveal(),
    $this->logger->reveal()
);

Quick mock for Methods

Is your feature request related to a problem? Please describe.
No

Describe the solution you'd like
I would love it if this would also work for any Methods and not just Constructors.
As an example where this might be helpful:
ArgumentResolvers in Symfony get passed both a Request and ArgumentMetadata Object which would be great targets for a Prophecy.

Describe alternatives you've considered
I considered opening a PR for this but I have no idea how these Plugins are written and have only limited experience with Kotlin / Java. I'd be open to collaborate on it though.

Prophesizing aliased dependancies uses aliases unaware

To Reproduce
Have a class with dependancies, which are defined using alias in constructor and not real class name.
Use QuickMock to create prohesies in its test class.

Observed result
Aliases are used as class names in prophesize() but were not defined

Expected behavior
Similar aliases are defined in test class use

Prophesize missing properties action

Additional helper would be great, which:

  1. Finds all private properties which are initialized in constructor
  2. Adds them to constructor with prophesize accordingly their classes from doc block

Use case:
When a test needs several more mocks which are not a part of subject constructor calls, developer could just add private properties and generate all prophesies by this magic feature

Objectprohpecy annotation

It would be nice if the annotations of the generated mocks would contain that its an Objectprophecy. For Example:

/** @var ProducerInterface|ObjectProphecy */
private $producer;

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/release.yml
  • actions/checkout v3
  • actions/setup-java v3
  • gradle/gradle-build-action v2
  • thebritican/fetch-latest-release v2.0.0
  • actions/upload-release-asset v1.0.2
  • ubuntu 18.04
.github/workflows/test.yml
  • actions/checkout v3
  • actions/setup-java v3
  • gradle/gradle-build-action v2
  • ubuntu 18.04
gradle
gradle.properties
settings.gradle
build.gradle
  • org.jetbrains.intellij 1.10.0
  • org.jetbrains.gradle.plugin.idea-ext 1.1.7
  • org.jetbrains.kotlin.jvm 1.7.22
  • junit:junit 4.13.2
gradle-wrapper
gradle/wrapper/gradle-wrapper.properties
  • gradle 7.6

  • Check this box to trigger a request for Renovate to run again on this repository

Plugin creates error if no constructor is present

Describe the bug
Plugin creates error if no constructor is present

To Reproduce

  • create class without constructor
  • create test for this class
  • use plugin intention to create mocks
  • error occurs

Expected behavior

  • no error should occur

Overwriting of PHPUnit TestCase properties

Describe the bug
When the tested class has parameters in the constructor which are named like properties of the PHPUnit TestCase class, these would be overwritten after using quickmock

To Reproduce
Steps to reproduce the behavior:

  1. Create a class with a contructor parameter called data
  2. Create a test for this class
  3. Use quickmock
  4. See error

Expected behavior
Maybe detection if TestCase already reservers a name and rename the generated property

Pass basic types parameters as class fields

Currently when a subject constructor requires e.g. string parameters they are passe simply as empty strings in the call.

The could be created as test class fields and passed respectively.

Benefit: these values can be used is assertions later on.

Make addition of doc blocks configurable

Is your feature request related to a problem? Please describe.
When creating new mock members of the test, a doc block is always generated. In case I am using other plugins like Haehnchen/idea-php-phpunit-plugin , I do not need these. Therefore I want to be able to disable doc block generation.

Describe the solution you'd like
A configuration page to disable generation of doc blocks.

Add ObjectProphecy to class properties if PHP version selected for the project is >= 7.4

Is your feature request related to a problem? Please describe.
PHP7.4 introduced class variable type-hinting. It would be great if the plugin could identify the selected php version for this project and if >= 7.4, could make a slight change to the mock declaration.

Describe the solution you'd like
Current behaviour:
/** @var DistributionRepository|ObjectProphecy */
private $distributionRepository;

Desired behaviour:
use Prophecy\Prophecy\ObjectProphecy;
/** @var DistributionRepository|ObjectProphecy */
private ObjectProphecy $distributionRepository;

PHP basic types are also being prophesized

If testing subject has dependancies of a basic type like array, string or integer, they are also added as prophesies. They could be added simply with an empty value of the corresponding type ([], '' or 0)

Format

For better readability i would suggest to put a newline between the generated prophecies and the subject class

incomplete mock generation

In some cases, the mock generation fails and creates code fragments like
$this->config = $this->prophesize(array::

In the background, an exception is thrown:

ERROR: The method designed for fully qualified names only. Got "array|string[]".
java.lang.Throwable: The method designed for fully qualified names only. Got "array|string[]".
	at com.intellij.openapi.diagnostic.Logger.error(Logger.java:123)
	at com.jetbrains.php.util.PhpContractUtil.assertFqn(PhpContractUtil.java:19)
	at com.jetbrains.php.codeInsight.PhpCodeInsightUtil.isSameNamespace(PhpCodeInsightUtil.java:662)
	at com.jetbrains.php.codeInsight.PhpCodeInsightUtil.alreadyImported(PhpCodeInsightUtil.java:841)
	at de.cawolf.quickmock.intention.service.AddMissingUseStatements.invoke(AddMissingUseStatements.kt:13)
	at de.cawolf.quickmock.intention.QuickMockCreator.invoke(QuickMockCreator.kt:71)

Context menu not showing up for classes with a contructor in abstract

Describe the bug
The context menu for adding constructor arguments is not showing up if your subject extends a class which holds the constructor without having a constructor on its own.

Expected behavior
Even though Abstraction could and should be avoided most of the time, sometimes you are stuck with legacy code where refactoring is currently not an option. So I beg you to implement this change :)

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.