Very new to php unit and can't exactly work out whats wrong. My class is as follows:
<?php
include $_SERVER['DOCUMENT_ROOT'] . '/assets/php/global_php_includes.php';
use PHPUnit\Framework\TestCase;
final class PesticideTests extends TestCase {
public function addPesticideTest() {
$data = array(
"code" => randomString(16),
"created_by" => $_SESSION['userCode'],
"company_code" => "TEST_COMPANY",
"crop_code" => "TEST_CROP",
"content" => "TEST_CONTENT",
"comments" => "TEST_COMMENTS",
"function" => "TEST_FUNCTION",
"pcs_no" => 0123,
"phi" => "TEST_PHI",
"product_name" => "TEST_PRODUCT",
"substance" => "TEST_SUBSTANCE",
"date_of_reg_review" => "01-01-0001",
"use_by_date" => "01-01-0001",
"off_label_approval" => "TEST_OFF_LABEL_APPROVED",
"latest_time_of_application" => "TEST_LATEST_TIME_OF_APPLICATION",
"max_individual_dose" => "TEST_MAX_INDIVIDUAL_DOSE",
"max_total_dose" => "TEST_MAX_TOTAL_DOSE",
"max_no_applications" => "TEST_MAX_NO_APPLICATIONS",
"method_of_application" => "TEST_METHOD_OF_APPLICATION",
"status" => 'inactive'
);
$result = addPesticide($connection, $data);
$this->assertEquals(1, $result);
}
}
the command I run to test it is ./vendor/bin/phpunit tests/PesticideTests.php
and the error I get is
PHP Warning: include(/assets/php/global_php_includes.php): failed to open stream: No such file or directory in C:\xampp\htdocs\tapp\tests\PesticideTests.php on line 3
Warning: include(/assets/php/global_php_includes.php): failed to open stream: No such file or directory in C:\xampp\htdocs\tapp\tests\PesticideTests.php on line 3
PHP Warning: include(): Failed opening '/assets/php/global_php_includes.php' for inclusion (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\tapp\tests\PesticideTests.php on line 3
Warning: include(): Failed opening '/assets/php/global_php_includes.php' for inclusion (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\tapp\tests\PesticideTests.php on line 3
PHPUnit 9.5.2 by Sebastian Bergmann and contributors.
W 1 / 1 (100%)
Time: 00:00.014, Memory: 4.00 MB
There was 1 warning:
1) Warning
No tests found in class "PesticideTests".
WARNINGS!
Anyone have any idea what I'm doing wrong? If I also run it as just ./vendor/bin/phpunit tests then I get the error "No tests found". Pretty confused
EDIT:
I have fixed the test not being found by naming it by the wrong convention, still getting an error for the include file
When running your code withing phpunit there is no $_SERVER['DOCUMENT_ROOT'] set. This only gets set when running in the context of a webserver. Just replace this with the directory where the assets directory is.
Related
I have installed OroCommerce, a Symfony2 based application. I want to have the 'vendor' directory on a higher level outside the users directory. I followed the steps at http://symfony.com/doc/current/configuration/override_dir_structure.html#override-the-vendor-directory but now the namespaces can't be found. I get the following error:
InvalidArgumentException in YamlFileLoader.php line 399: There is no extension able to load the configuration for "framework" (in /home/oro2/public_html/app/config/config_dev.yml). Looked for namespace "framework", found "web_profiler", "sensio_distribution", "debug"
in YamlFileLoader.php line 399
at YamlFileLoader->validate(array('imports' => array(array('resource' => 'config.yml')), 'framework' => array('router' => array('resource' => '%kernel.root_dir%/config/routing_dev.yml'), 'profiler' => array('only_exceptions' => false)), 'web_profiler' => array('toolbar' => true, 'intercept_redirects' => false), 'monolog' => array('handlers' => array('main' => array('type' => 'stream', 'path' => '%kernel.logs_dir%/%kernel.environment%.log', 'level' => 'debug'))), 'oro_assetic' => array('css_debug' => null, 'css_debug_all' => false), 'oro_message_queue' => array('client' => array('traceable_producer' => true))), '/home/oro2/public_html/app/config/config_dev.yml') in YamlFileLoader.php line 369
at YamlFileLoader->loadFile('/home/oro2/public_html/app/config/config_dev.yml') in YamlFileLoader.php line 44
at YamlFileLoader->load('/home/oro2/public_html/app/config/config_dev.yml', null) in DelegatingLoader.php line 45
at DelegatingLoader->load('/home/oro2/public_html/app/config/config_dev.yml') in AppKernel.php line 35
at AppKernel->registerContainerConfiguration(object(DelegatingLoader)) in bootstrap.php.cache line 2776
at Kernel->buildContainer() in bootstrap.php.cache line 2728
at Kernel->initializeContainer() in OroKernel.php line 290
at OroKernel->initializeContainer() in bootstrap.php.cache line 2507
at Kernel->boot() in OroKernel.php line 252
at OroKernel->boot() in bootstrap.php.cache line 2538
at Kernel->handle(object(Request)) in app_dev.php line 33
Am I forgetting something? Does anyone know how to solve this problem?
You are somewhere calling %kernel.root_dir%/config/routing_dev.yml which actually does not exist, because you have moved the config file dir
Recently I've updated my composer to 1.0.3. After that I'm getting following error. "PHP Fatal error: Cannot redeclare class Error"
Here is my sample code.
<?php
require "./vendor/autoload.php";
require "MyErrorLog.php"; // Class file having class name as "Error"
Previously, I was using some code without having any problem. But, after updating composer & it's dependance I'm getting this error.
Shall I need to use a namespace to resolve this or something else I need to do?
If I use following the piece of code.
require "./vendor/autoload.php";
$Error = new Error();
echo '<pre>';
print_r($Error);
echo '</pre>';
I'm getting this out put.
Error Object
(
[message:protected] =>
[string:Exception:private] =>
[code:protected] => 0
[file:protected] => /var/www/testing/composer-test1/composer-test.php
[line:protected] => 7
[trace:Exception:private] => Array
(
)
[previous:Exception:private] =>
)
Anyone, help me to understand what's exactly it is & what it's uses?
Adding my composer.json file content
{
"require": {
"defuse/php-encryption": "^2.0"
}
}
I m trying to implement Knp SNappy Bundle to display an html page as a pdf from my controller.
I'm stuck with this error :
The exit status code '1' says something went wrong:
stderr: "Loading pages (1/6)
[> ] 0%
[======> ] 10%
[==========> ] 18%
Warning: Failed to load file:///slick/slick.css (ignore)
Warning: Failed to load file:///slick/slick-theme.css (ignore)
Warning: Failed to load file:///clovis-app/style.css (ignore)
Warning: Failed to load file:///clovis-app/estimate.css (ignore)
Warning: Failed to load file:///clovis-app/res/clovis.png (ignore)
Warning: Failed to load file:///js/collection.js (ignore)
Warning: Failed to load file:///clovis-app/script.js (ignore)
Warning: Failed to load file:///clovis-app/estimate.js (ignore)
[============================================================] 100%
Counting pages (2/6)
[============================================================] Object 1 of 1
Resolving links (4/6)
[============================================================] Object 1 of 1
Loading headers and footers (5/6)
Printing pages (6/6)
[> ] Preparing
[===================> ] Page 1 of 3
[=======================================> ] Page 2 of 3
[============================================================] Page 3 of 3
Done
Exit with code 1 due to network error: ContentOperationNotPermittedError"
stdout: ""
command: "C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe" --lowquality "C:\Users\Razgort\AppData\Local\Temp\knp_snappy55ae6cc4ad0353.17775155.html" "C:\Users\Razgort\AppData\Local\Temp\knp_snappy55ae6cc4ad41d0.64896673.pdf".
Here is my configuration file :
knp_snappy:
pdf:
enabled: true
binary: "\"C:\\Program Files\\wkhtmltopdf\\bin\\wkhtmltopdf.exe\""
options: []
image:
enabled: true
binary: "\"C:\\Program Files\\wkhtmltopdf\\bin\\wkhtmltoimage.exe\""
options: []
and here is how i render the view :
$html = $this->renderView('CompanyBundle:Estimate:edit.html.twig', array(
'estimate' => $estimate,
'estimateForm' => $estimateForm->createView(),
'articleForm' => $articleForm->createView(),
'articleSelectForm' => $articleSelectForm->createView(),
'manpowerForm' => $manpowerForm->createView(),
'manpowerSelectForm' => $manpowerSelectForm->createView(),
'workSelectForm' => $workSelectForm->createView(),
'workForm' => $workForm->createView(),
'bundleForm' => $bundleForm->createView(),
'bundleSelectForm' => $bundleSelectForm->createView(),
));
return new Response(
$this->get('knp_snappy.pdf')->getOutputFromHtml($html),
200,
array(
'Content-Type' => 'application/pdf',
'Content-Disposition' => 'attachment; filename="file.pdf"'
)
);
I eard there is problems on MAMP, i use wamp, didn't see any issue with it.
I'll really appreciate some help on this =)
Edit :
I modified some things in order to generate a pdf first. And i did. But the pdf only contents my login page. Then i added the access to my session and it worked. But when i try to send it as a response like that :
$session = $this->get('session');
$session->save();
session_write_close();
$pageUrl = $this->generateUrl('estimate_preview', array('id' => $id), true);
return new Response(
$this->get('knp_snappy.pdf')->getOutput($pageUrl, array('cookie' => array($session->getName() => $session->getId()))),
200,
array(
'Content-Type' => 'application/pdf',
'Content-Disposition' => 'attachment; filename="file.pdf"'
)
);
it doesn't seem to work either... Does someone have an idea why ?
Try by using forward (getContent()) method instead render.
$html = $this->forward('CompanyBundle:Estimate:edit.html.twig', array(
'estimate' => $estimate,
'estimateForm' => $estimateForm->createView(),
'articleForm' => $articleForm->createView(),
'articleSelectForm' => $articleSelectForm->createView(),
'manpowerForm' => $manpowerForm->createView(),
'manpowerSelectForm' => $manpowerSelectForm->createView(),
'workSelectForm' => $workSelectForm->createView(),
'workForm' => $workForm->createView(),
'bundleForm' => $bundleForm->createView(),
'bundleSelectForm' => $bundleSelectForm->createView(),
))->getContent();
$pdf =$this->get('knp_snappy.pdf')->getOutputFromHtml($html);
First check by printing $pdf and then you can return it as a response.
Do this for all your CSS files in your Twig:
<link rel="stylesheet" href="{{ app.request.scheme ~'://'~ app.request.httpHost ~ asset('css/my_custom_stylesheet.css') }}" />
The CSS folder must be directly under /web
Knp SNappy Bundle is a wrapper. In your symphony side you do all right.
But in your HTML-to-render you have relative URLs, that is not absolute to HTTP-server. So when wkhtmltopdf see in your HTML url like '/dsasdaasd/sdaasd.wtf', it does not know, that it's your site.
1st option. Render PDF by URL (pass some option like "use print styles").
2nd: Use in your HTML absolute pathes to assets.
Anyway there is no absolute correct HTML, so you can meet in the future more errors like this -- even if in huge HTML there will be only one not-found-image. So try to find some options in snappy to ignore these errors as in the result pdf will be generated ok.
I have installed WAMP server with following details
1. Apache httpd 2.2.22
2. PHP 5.4.3
3. MySQL 5.5.24
I want to run Symfony2 on this so I downloded this
Symfony_Standard_Vendors_2.2.1
And tried to make application from it
I am getting following error for it
1/1 InvalidArgumentException: There is no extension able to load the configuration for "framework" (in D:\Program files\wamp\www\Symfony\app/config/config_dev.yml). Looked for namespace "framework", found "security", "twig", "monolog", "swiftmailer", "assetic", "doctrine", "sensio_framework_extra", "jms_aop", "jms_di_extra", "jms_security_extra", "acme_demo", "web_profiler", "sensio_distribution"
in D:\Program files\wamp\www\Symfony\vendor\symfony\symfony\src\Symfony\Component\DependencyInjection\Loader\YamlFileLoader.php line 268
at YamlFileLoader->validate(array('imports' => array(array('resource' => 'config.yml')), 'framework' => array('router' => array('resource' => '%kernel.root_dir%/config/routing_dev.yml'), 'profiler' => array('only_exceptions' => false)), 'web_profiler' => array('toolbar'
=> true, 'intercept_redirects' => false), 'monolog' => array('handlers' => array('main' => array('type' => 'stream', 'path'
=> '%kernel.logs_dir%/%kernel.environment%.log', 'level' => 'debug'), 'firephp' => array('type' => 'firephp', 'level' => 'info'), 'chromephp' => array('type' => 'chromephp', 'level' => 'info'))), 'assetic' => array('use_controller' => true)), 'D:\Program files\wamp\www\Symfony\app/config/config_dev.yml') in D:\Program files\wamp\www\Symfony\vendor\symfony\symfony\src\Symfony\Component\DependencyInjection\Loader\YamlFileLoader.php line 238
at YamlFileLoader->loadFile('D:\Program files\wamp\www\Symfony\app/config/config_dev.yml') in D:\Program files\wamp\www\Symfony\vendor\symfony\symfony\src\Symfony\Component\DependencyInjection\Loader\YamlFileLoader.php line 42
at YamlFileLoader->load('D:\Program files\wamp\www\Symfony\app/config/config_dev.yml', null) in D:\Program files\wamp\www\Symfony\vendor\symfony\symfony\src\Symfony\Component\Config\Loader\DelegatingLoader.php line 52
at DelegatingLoader->load('D:\Program files\wamp\www\Symfony\app/config/config_dev.yml') in D:\Program files\wamp\www\Symfony\app\AppKernel.php line 36
at AppKernel->registerContainerConfiguration(object(DelegatingLoader)) in D:\Program files\wamp\www\Symfony\app\bootstrap.php.cache line 653
at Kernel->buildContainer() in D:\Program files\wamp\www\Symfony\app\bootstrap.php.cache line 593
at Kernel->initializeContainer() in D:\Program files\wamp\www\Symfony\app\bootstrap.php.cache line 378
at Kernel->boot() in D:\Program files\wamp\www\Symfony\app\bootstrap.php.cache line 409
at Kernel->handle(object(Request)) in D:\Program files\wamp\www\Symfony\web\app_dev.php line 26
Not able to understand, how solve this problem ?
or where is the issue ?
Have you ran check.php, config.php as nicely described in the README.md? I would also recommend to use Symfony with composer, instead of with vendors. Please check the documentation for a proper setup.
This kind of error is usually thrown if you forgot to register a bundle and have already put bundle-specific configurations into app/config/config.yml.
The 'framework' configuration namespace is provided by the FrameworkBundle.
Please make sure you have FrameworkBundle registered in your app/AppKernel.php
<?php
[...]
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
[...]
Please also clear your cache with app/console cache:clear ( probably not working aswell ) or remove the contents of app/cache folder manually.
I'm doing all of this locally for testing purposes right now. I ran the service project in visual studio and have my local version of the site setup to make the call to the web service but it won't hit it.
Here's the call:
$client = new SoapClient(null, array('location' => "https://localhost:51063/Service1.asmx", 'uri' => 'http://localhost:51063/'));
$client->newMeeting(array('id' => '10000', 'location' => 'test', 'committee' => 'test', 'desc' => 'test', 'date' => '2011-08-01', 'duration' => '180', 'agenda' => '', 'notes' => '', 'agenda' => '', 'notes' => ''));
And using that I get this error:
Uncaught SoapFault
Could not connect to host
Trace in execution order:
Dispatcher→dispatch(null, 'page') on line 98 in C:\xampp\htdocs\narca\admin\index.php
Dispatcher→executeAction('plugin', 'committees', array[1]) on line 162 in C:\xampp\htdocs\narca\frog\Framework.php
PluginController→execute('committees', array[1]) on line 247 in C:\xampp\htdocs\narca\frog\Framework.php
call_user_func_array(array[2], array[0]) on line 84 in C:\xampp\htdocs\narca\frog\app\controllers\PluginController.php
CommitteesController→addevent() on line unknown in unknown
SoapClient→newMeeting(array[8]) on line 429 in C:\xampp\htdocs\narca\frog\plugins\committees\CommitteesController.php
SoapClient→__call('newMeeting', array[1]) on line unknown in unknown
SoapClient→__doRequest('<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:...', 'https://localhost:51063/Service1.asmx', 'http://localhost:51063/#newMeeting', 1, 0) on line unknown in unknown
If I try to call it like this:
$client = new SoapClient("https://localhost:51063/Service1.asmx?WSDL");
I get a different error:
Uncaught SoapFault
SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://97.67.111.2:51063/Service1.asmx?WSDL' : failed to load external entity "http://97.67.111.2:51063/Service1.asmx?WSDL"
Trace in execution order:
Dispatcher→dispatch(null, 'page') on line 98 in /mnt/stor2-wc1-dfw1/410993/410996/lab.narca.org/web/content/admin/index.php
Dispatcher→executeAction('plugin', 'committees', array[1]) on line 162 in /mnt/stor2-wc1-dfw1/410993/410996/lab.narca.org/web/content/frog/Framework.php
PluginController→execute('committees', array[1]) on line 247 in /mnt/stor2-wc1-dfw1/410993/410996/lab.narca.org/web/content/frog/Framework.php
call_user_func_array(array[2], array[0]) on line 84 in /mnt/stor2-wc1-dfw1/410993/410996/lab.narca.org/web/content/frog/app/controllers/PluginController.php
CommitteesController→addevent() on line unknown in unknown
SoapClient→SoapClient('http://97.67.111.2:51063/Service1.asmx?WSDL') on line 423 in /mnt/stor2-wc1-dfw1/410993/410996/lab.narca.org/web/content/frog/plugins/committees/CommitteesController.php
Is this setup even possible? Or is there a way I can make the live site hit my local service?
Can you fetch that URL from the server PHP is on, using curl or something similar? Is there a firewall somewhere that blocks those high-numbered-post requests? Your PHP looks fine so I don't think you are doing anything wrong there.