I integrated PHPUnit into netbeans and now want to generate tests for my code.
<?php
/**
* Action User
*
* user api
*
* #link http://getfrapi.com
* #author Frapi <frapi#getfrapi.com>
* #link rsmobile/user/:id
*/
class Action_User extends Frapi_Action implements Frapi_Action_Interface
{
}
?>
I tried to do that by right clicking and selecting Tools->Create PHPUnit Tests. But it gave this error :
Fatal error: Class 'Frapi_Action' not found in /Users/username/Documents/.../src/
frapi/custom/Action/User.php on line 12
Then I added dummy Frapi_Action class in file User.php and then it generated skeleton class.
<?php
/**
* Action User
*
* user api
*
* #link http://getfrapi.com
* #author Frapi <frapi#getfrapi.com>
* #link rsmobile/user/:id
*/
class Frapi_Action {}
class Action_User extends Frapi_Action implements Frapi_Action_Interface
{
}
?>
Why it gave that Class not found error? How do I solve it?
I solved it by adding path of the file containing Frapi_Action class.
require_once 'path/of/file';
Your class is not in the source code in the original example. You either need to include/require the external file containing the class (recommended) or have the class in this code.
Related
I am having a lot of trouble getting PHPStan to see the FuelPHP core classes. It would appear this sort of thing causes it grief:
namespace Fuel\Core;
/**
* Template Controller class
*
* A base controller for easily creating templated output.
*
* #package Fuel
* #category Core
* #author Fuel Development Team
*/
abstract class Controller_Template extends \Controller
{
/**
* #var string page template
*/
public $template = 'template';
Where Controller is also in the Fuel\Core namespace:
namespace Fuel\Core;
abstract class Controller
{
/**
* #var Request The current Request object
*/
public $request;
It looks like PHPStan can's find Controller because it is looking in the root namespace. FuelPHP gets around this (magic? autoloading? aliasing?). Is there a way to get PHPStan to jump on the same bandwagon, or do I need to stub out all the core classes I'm using?
Did you try to follow this guide? PHPStan: Discovering symbols
I helped set up FuelCMS analysis in the past. What worked for that user was this phpstan.neon:
parameters:
scanDirectories:
- core/classes
bootstrapFiles:
- core/classes/autoloader.php
There's an example repository that works: https://github.com/ondrejmirtes/phpstan_problem/tree/fix
For some reason the phpstan.neon is buried in app/classes/controller while it should definitely be in the root directory. But otherwise it works.
Is there any way to suppress particular types of errors in PHPDoc, or direct it not to check for some elements?
I don't need a DocBlock for both the file and the class. My typical layout is as follows:
<?php
/**
* Registration service
*
* Coordinates the registration actions for users. These are ...
*
* #version a.4.2
* #author My Name <me at example.com>
*/
namespace MyProject\Service;
use Other\Namespace;
class Registration extends AbstractService
{
// ...
In this case, PHPDoc complains that I have no class summary. I can remedy the problem by copying the DocBlock and pasting it immediately above the class declaration, but I'm hoping for a better solution.
If I'm not mistaken, and I didn't test this, you could do something like this:
<?php
namespace MyProject\Service;
use Other\Namespace;
/**
* Registration service
*
* Coordinates the registration actions for users. These are ...
*
* #version a.4.2
* #author My Name <me at example.com>
*/
class Registration extends AbstractService
{
// ...
At least the docblock should now be recognised as a class doc instead of a file doc, which is more accurate in this particular example.
To try and answer your original question, actually suppressing the error, you could try this answer (it describes using the command line --packageoutput argument).
I am building an application using Zend Framework and Doctrine 2.
My code looks like this:
namespace Entities;
use Doctrine\Common\Collections\ArrayCollection;
/**
* #Entity (repositoryClass="Repositories\Person")
* #Table(name="persons")
* #InheritanceType("SINGLE_TABLE")
* #DiscriminatorColumn(name="type", type="string")
* #DiscriminatorMap({"2"="User"})
*/
class Person
{
/**
* #Id #Column(type="integer")
* #GeneratedValue(strategy="AUTO")
*/
private $id;
}
And my class User
namespace Entities;
use Doctrine\Common\Collections\ArrayCollection;
/**
* #Entity (repositoryClass="Repositories\User")
*/
class User extends Person
{
}
Now, I get this error:
Fatal error: Class 'Entities\Person' not found in C:\xamp\htdocs\Persons\application\m
odels\Entities\User.php on line 13
I have no idea why I get that error. I have tried calling the "Person" class in many different ways but the its not working. Any idea? Thanks!
When running in Zend Framework, you have an autoloader setup that handles the loading of classes for you dynamically.
When you run just the Doctrine tool from the command line, you don't have an autoloader at your disposal. Doctrine is trying to load the User class, which requires Person, and yet it doesn't (apparently) know how to load Person.
I think the simple solution would be to have require_once('Person.php'); at the top of your User entity. This is probably unnecessary for ZF, but will be helpful for Doctrine command line tools.
PHPDocumenter keeps telling me that my page-level docblock is not present in my file, i read several pages of documentation online to make this work but still doesn't work, anyone know whats wrong?
<?php
namespace Activis\Catalog\Model;
/**
* This file represents the factory for the domain object Product for the Activis catalog.
*
* For now, this factory is simple and abstract but will slowly change into a non-static set of factory functions
* The domain model for this object is \Activis\Catalog\Model\Product
*
* #category Domain model factory
* #package Activis.Catalog.Model
* #author Mathieu Dumoulin
* #license LGPL v3
* #link http://activis.ca/
* #todo Change the methods in the factory to not be abstract and require an instance of this class
*/
/**
* Declares the catalog's product's domain model factory
*
* #abstract
* #static
*/
abstract class ProductFactory
{
}
Page-level docblock should be placed on top of file, before namespace declarations
My code looks like this:
/**
* #package Test
*/
require_once('foo.php');
/**
* Main class
*/
class Test{
}
/**
* Generic exception
*/
class Test_Excepcion extends Exception{
}
I want the first docblock to be a file level block, but ApiGen seems to link it to the require statement and my classes show up in the "None" namespace. It gets fixed if I do e.g. this:
/**
* #package Test
*/
//
require_once('foo.php');
Is this the intended behaviour? Do I need to add a bogus comment after the file level block? What are the precise rules?
The #package tag is not necessarily a file-level block. You can specify the #package tag for each class in your file. Like this:
/**
* Main class
* #package Test
*/
class Test{}