can't test eloquent with php unit - testing

I try to implement some unit tests with phpUnit, on a project that uses Eloquent. The installation is made with composer for both frameworks. But when I try to implement a simple example test, it fails loading database.php
the example test
include("database.php");
class ArticleControllerTest extends TestCase
{
public function testAccueil()
{
//récupère la date du jour
$a = \app\model\Article::first();
$this->assertInternalType("string", $a->titreGeneral);
}
}
Database.php
<?php
require 'vendor/autoload.php';
use Illuminate\Container\Container;
use Illuminate\Database\Capsule\Manager as Capsule;
use Illuminate\Events\Dispatcher;
$capsule = new Capsule;
$capsule->addConnection(array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'spectacles',
'username' => 'root',
'password' => 'root',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => ''
));
$capsule->setEventDispatcher(new Dispatcher(new Container));
$capsule->setAsGlobal();
$capsule->bootEloquent();
error message with these script (the database is in the right folder)
PHP Warning: include(../../database.php): failed to open stream: No such file or directory in /Applications/MAMP/htdocs/spectacles/TestUnits/controllerTest/ArticleControllerTest.php on line 6
Warning: include(../../database.php): failed to open stream: No such file or directory in /Applications/MAMP/htdocs/spectacles/TestUnits/controllerTest/ArticleControllerTest.php on line 6
PHP Warning: include(): Failed opening '../../database.php' for inclusion (include_path='.:') in /Applications/MAMP/htdocs/spectacles/TestUnits/controllerTest/ArticleControllerTest.php on line 6
Warning: include(): Failed opening '../../database.php' for inclusion (include_path='.:') in /Applications/MAMP/htdocs/spectacles/TestUnits/controllerTest/ArticleControllerTest.php on line 6
And error messages when I try to put the code in database.php directly in the example test :
PDOException: SQLSTATE[HY000] [2002] No such file or directory
I don't think the problem comes prom the paths (they are the right paths). Did I miss something ?

PDOException: SQLSTATE[HY000] [2002] No such file or directory means the database could not connect.
The other errors are clearly telling you that the script could not include the database.php file.
The paths are not correct. You are not properly understanding how include() works. Read http://php.net/manual/en/function.include.php.
In a nutshell, the following code expects the database.php file to exist in the same directory as the file itself, or on the include path.
include("database.php");
class ArticleControllerTest extends TestCase
{
...
These may also help:
Understanding include_path output PHP
Include Config and Database from other files

Related

Puppet conditional only if file exists in a particular directory

I have the following file resource in my puppet manifest:
file{
'example.dat'
path => "/path/to/example.dat",
owner => devops,
mode => "0644",
source => "/path/to/example.txt"
}
I want to run the above snippet only when the .txt file is present in a particular directory. Otherwise, I do not want the snippet to run.
How do I go about doing that in puppet?
In general, you would create a custom fact that returns true when the directory in question satisfies your condition. For example:
Facter.add('contains_txt') do
setcode do
! Dir.glob("/path/to/dir/*.txt").empty?
end
end
Then you would write:
if $facts['contains_txt'] {
file { 'example.dat':
path => "/path/to/example.dat",
owner => devops,
mode => "0644",
source => "/path/to/example.txt",
}
}

Jenkins cannot find file even though it exist in the workplace Selenium File not found: Selenium::WebDriver::Error::InvalidArgumentError)

So I am seeing this below, the file exist and this is the ruby line of code thats supposed to run:
upload = #browser.file_field(:type => 'file', :class => 'react-fine-uploader-file-input')
upload.send_keys("workplace/uploads/test1.mp3")
#browser.button(:class => 'change-file-button').wait_until_present
Jenkins error below in the console output:
File not found: workplace/uploads/test1.mp3
(Selenium::WebDriver::Error::InvalidArgumentError)

why chef-metal-ssh is failed

I was trying to follow https://github.com/double-z/chef-metal-ssh
I'm running the code below, it throws the exception:
[2015-01-19T06:03:39-06:00] ERROR: machineone had an error: ArgumentError: wrong number of arguments (2 for 0)
require 'chef_metal_ssh'
name = "one"
with_ssh_cluster("~/metal_ssh")
machine name do
action [:ready, :converge]
machine_options 'ip_address' => '10.62.56.209',
'ssh_options' => {
'user' => 'root',
'keys' => ['/home/chefuser/test.rsa']
}
files '/remote/path.txt' => { :content => 'foo' }
end
machine_execute name do
command "pwd" # this uses new_daemon_key to register with halo
end
I want to know what's wrong of this code. And I don't understand for with_ssh_cluster("~/metal_ssh") what content should be in "~/metal_ssh"? thanks.
I had to dig a little with the code to understand (I'm not using it).
According to the comment below found here
# cluster_path - path to the directory containing the vagrant files,
# which should have been created with the vagrant_cluster resource.
The "~/metal_ssh" file should be the Vagrantfile path.
chaf-metal-ssh is a driver for chef-metal, I'm not sure you're comfortable with chef-metal, so I would advise starting by reading This and This
I've found that the issue is I was using chef 12.0.3, and in line 109 of /usr/local/rvm/gems/ruby-2.0.0-p598/gems/chef-12.0.3/lib/chef/dsl/recipe.rb
resource.load_prior_resource(type, name)
But in chef-metal-ssh-0.1.2/lib/chef/resource/ssh_cluster.rb:18
it's defined as
def load_prior_resource
Chef::Log.debug("Overloading #{resource_name}.load_prior_resource with NOOP")
end
so it throws
ArgumentError: wrong number of arguments (2 for 0)

Bigcommerce Class 'Bigcommerce\Api\Error' not found

I keep getting this error when I try to execute a simple script on the server while it runs fine on my local machine.
Error
Fatal error: Class 'Bigcommerce\Api\Error' not found in
/customers/0/4/1/myDomainName/httpd.www/demo/hello/bigcommerce.php on
line 370
link to API
Sample Code
require_once 'bigcommerce.php';
use Bigcommerce\Api\Client as Bigcommerce;
Bigcommerce::configure(array(
'store_url' => 'https://www.mystore.com/',
'username' => 'myUsername',
'api_key' => 'myPass'
));
Bigcommerce::setCipher('RC4-SHA');
Bigcommerce::verifyPeer(false);
?>
Php Version
Server: 5.3.23
Local: 5.3.13
I fixed it by moving the declaration of class Error to just above the line 370 where class ClientError was declared.

Fatal error: Undefined class constant 'ACL_PUBLIC_READ'

I downloaded AWS SDK and stored it in the same directory of this file, but every tyme this simple script gives this error:
"Fatal error: Undefined class constant 'ACL_PUBLIC_READ'"
This script is for uploading a simple png image on s3:
require 'aws.phar';
$bucket='example';
use Aws\S3\S3Client;
use Aws\Common\Enum\Region;
$client = S3Client::factory(array(
'key' => 'mykey',
'secret' => 'mysecretkey'
));
$client->putObject($_FILES['myfile']['tmp_name'], $bucket , 'file.png', S3Client::ACL_PUBLIC_READ);
How can I solve it?
That constant doesn't exist in SDK 2.x. I think you're looking for this:
http://docs.aws.amazon.com/aws-sdk-php-2/latest/class-Aws.S3.Enum.CannedAcl.html