PHP Classes

PHP Shop Simulator in the Console: Simulate shopping purchases in a console

Recommend this page to a friend!
  Info   Example   Screenshots   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 37 All time: 10,956 This week: 673Up
Version License PHP version Categories
console-shop-to-php 1MIT/X Consortium ...7E-Commerce, Console, PHP 7, Business
Description 

Author

This package can simulate shopping purchases in a console.

It provides several classes that model products, items, and cash amounts.

The package provides a script with functions that allow the users to pick products, quantities, and amounts that can pay for the products they decide.

Innovation Award
PHP Programming Innovation award nominee
June 2022
Number 2
Testing is an important step that all application developers should perform to assure the quality of crucial aspects of their software applications.

There are many types of testing. A kind of testing is called human testing.

In human testing, real people test an application and try to achieve a goal, like, for instance, purchasing on a Web site.

This package provides a way to perform human testing of class components that developers can use to implement a shopping site.

It allows users to perform tests in the command line console shell using an application that can take input from users, pick products, and simulate purchases, so they can verify if the shopping application works as expected.

This way, developers can test the shopping application components without using a Web server.

Manuel Lemos
Picture of adam berger
  Performance   Level  
Name: adam berger <contact>
Classes: 23 packages by
Country: Poland Poland
Age: ???
All time rank: 74521 in Poland Poland
Week rank: 200 Up2 in Poland Poland Up
Innovation award
Innovation award
Nominee: 8x

Winner: 2x

Example

<?php
declare(strict_types=1);

require_once
'./vendor/autoload.php';

use
ConsoleShopPHP\ClassApp\Product;
use
ConsoleShopPHP\ClassApp\Items;
use
ConsoleShopPHP\ClassApp\Cash;

use
ConsoleShopPHP\appInterface\Shop\ShopInterface;
use
ConsoleShopPHP\appInterface\Exception\ProgramsException;
use
ConsoleShopPHP\appInterface\Items\ItemsInterface;
use
ConsoleShopPHP\appInterface\Cash\CashInterface;


try{
    echo
"Enter the Product?
     Product <--> A 0.65 $,
      Product <--> B 1 $,
       Product <--> C 2,5 $,
        Product <--> D 5.75 $,
         Exit <--> E of e: \n"
;
echo
"Input: ";
   
$tabLineProduct = ["A"=>true, "B"=>true, "C"=>true, "D"=>true];

    do{
       
$line = trim(handleLine());
       
// Wyjscie
       
exitMachine($line);
       
// Wszystkie symbole oprócz tablicy
       
if(@is_null($tabLineProduct[$line])){
           
$tabLineProduct[$line] = false;
       
// throw new ProgramsException("empty index");
       
}

        if(
$tabLineProduct[$line] === true){
   
           
$product = new Product($line);
       
           
stringoTo("The cost of the product is: ", $product);
           
           
textCash();
   
        }else{
            echo
"There is no such product symbol ABORTING!\n";
            echo
"Enter the correct symbol A, B, C, D !\n";
            echo
"Enter the Product?
             Product <--> A 0.65 $,
              Product <--> B 1 $,
               Product <--> C 2,5 $,
                Product <--> D 5.75 $
                 Exit <--> E of e: \n"
;
        }
   
    }while(
$tabLineProduct[$line] !== true );
   
   
$cash = Cash::getInstance();
   
$items = Items::getInstance();
   
$tabLineMoney = ["P"=>true, "J"=>true, "T"=>true, "F"=>true, "D"=>true,"RM"=>false];

    do{
         echo
"Input: ";
       
$line = trim(handleLine());
       
// Wyjscie
       
exitMachine($line);
       
// Wszystkie symbole oprócz tablicy
       
if(@is_null($tabLineMoney[$line])){
           
$tabLineMoney[$line] = -1;
          
// throw new ProgramsException("empty index");
       
}
   
// RETURN-MONEY RM usun monety
       
if($tabLineMoney[$line] === false){
               
emptyCash($cash);
               
emptyItems($items);
            echo
"Coins cleared! \n";
            echo
"Enter the symbol correctly or remove the coins\n";
        }else{

            if(
$tabLineMoney[$line] === true){
   
               
$cash->addTypeCash($line);
               
$items->addTypeItems($line);
                           
// Dodaje z automatu
                           
addCash($cash);
                        echo
sumCash($cash)." $ ";
                           
addItems($items);
                        echo
allItems($items)." \n";
                    if(
$product->typeProduct > sumCash($cash)){
                        echo
"not enough! \n\n";
                    }
            }else{
                echo
"No such cash symbol ABORTING!\n";
               
textCash();
            }
        }
    }while(
$product->typeProduct > sumCash($cash));
   
    
$c = (int)(sumCash($cash)*1000);
    
$p = (int)($product->typeProduct*1000);
   
    echo
'The product purchased '.$product->typeProduct." $ and the return to the account is: ".(($c - $p)/1000)." $";
    echo
"\n";
    echo
"Thank you...\n\n\n\n\n";

}catch(
ProgramsException $e){
    echo
$e->getMessage();
}

function
stringoTo($text, ShopInterface $value ):void{
         print
$text.$value." $";
}

function
addCash(CashInterface $cash):void{
           
$cash->add();
}

function
sumCash(CashInterface $cash):float{
        return
$cash->sum();
}

function
emptyCash(CashInterface $cash):void{
           
$cash->empty();
}

function
addItems(ItemsInterface $items){
           
$items->add();
}

function
allItems(ItemsInterface $items):string{
        return
$items->itemAll();
}

function
emptyItems(ItemsInterface $items){
   
$items->empty();
}


function
handleLine(){
   
$handle = fopen ("php://stdin","r");
   
$line = fgets($handle);
    return
$line;
}

function
exitMachine($line):void {
    if(
$line == 'E' || $line == 'e'){
        echo
"ABORTING!\n\n\n\n\n";
        exit;
    }
}

function
textCash(){
echo
"
Enter the cash correctly or remove it money:
      0,05 $ --> P,
      0,1 $ --> J,
      0,25 $ --> T,
      0,5 $ --> F,
      1,00 $ --> D
      RETURN-MONEY --> RM Empty money
      Cash. I'm waiting? ;) : \n\n"
;
}


Details

Console Shop To PHP

Simple shopping store simulator in console

vendor and autoload

Console:

$ php composer.phar update

$ php index.php

ConsolaShopPHP


Screenshots (1)  
  • Consola-Shop-PHP
  Files folder image Files (12)  
File Role Description
Files folder imageapp (2 directories)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file index.php Example Example script
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files (12)  /  app  
File Role Description
Files folder imageappInterface (4 directories)
Files folder imageClassApp (3 files)

  Files folder image Files (12)  /  app  /  appInterface  
File Role Description
Files folder imageCash (1 file)
Files folder imageException (1 file)
Files folder imageItems (1 file)
Files folder imageShop (1 file)

  Files folder image Files (12)  /  app  /  appInterface  /  Cash  
File Role Description
  Plain text file CashInterface.php Class Class source

  Files folder image Files (12)  /  app  /  appInterface  /  Exception  
File Role Description
  Plain text file ProgramsException.php Class Class source

  Files folder image Files (12)  /  app  /  appInterface  /  Items  
File Role Description
  Plain text file ItemsInterface.php Class Class source

  Files folder image Files (12)  /  app  /  appInterface  /  Shop  
File Role Description
  Plain text file ShopInterface.php Class Class source

  Files folder image Files (12)  /  app  /  ClassApp  
File Role Description
  Plain text file Cash.php Class Class source
  Plain text file Items.php Class Class source
  Plain text file Product.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 91%
Total:37
This week:0
All time:10,956
This week:673Up